RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
THeaderControl.Sections Property

Lists the header sections (column headings).

Pascal
property Sections: THeaderSections;
C++
__property THeaderSections Sections;

The Sections property holds a THeaderSections—that is, a collection of THeaderSection objects. At design time, header sections can be added, removed, or modified with the Sections editor. To open the Sections editor, select the Sections property in the Object Inspector, then double-click in the Value column to the right or click the ellipsis (...) button.  

C++ Examples: 

 

/*
Add a THeaderControl to the form and call 
HeaderControl1DrawSection for the OnDrawSection event.
*/
void __fastcall TForm1::HeaderControl1DrawSection(THeaderControl *HeaderControl,
      THeaderSection *Section, const TRect &Rect, bool Pressed)
{
  if (Pressed)
    HeaderControl->Canvas->Font->Color = clRed;
  else
    HeaderControl->Canvas->Font->Color = clBlue;
  HeaderControl->Canvas->TextOut(Rect.Left + HeaderControl->Canvas->Font->Size, Rect.Top + 2, "Custom " + IntToStr(Section->Index));
}

void __fastcall TForm1::FormCreate(TObject *Sender)
{
  THeaderSection *Section;
  for (int i = 0; i <= 4; i++)
  {
    Section = HeaderControl1->Sections->Add();
    Section->Text = "Section " + IntToStr(i);
    Section->MinWidth =
      (Section->Text).Length() *
      HeaderControl1->Font->Size;
    // Owner draw every other section
    if (i % 2 == 0)
      Section->Style = hsOwnerDraw;
    else
      Section->Style = hsText;
  }
}

 

Delphi Examples: 

{
Add a THeaderControl to the form and call 
HeaderControl1DrawSection for the OnDrawSection event.
}
procedure TForm1.FormCreate(Sender: TObject);
var
  HeaderSection: THeaderSection;
  I: Integer;
begin
  for I := 0 to 4 do
  begin
    HeaderSection := HeaderControl1.Sections.Add;
    HeaderSection.Text := 'Text Section ' + IntToStr(I);
    HeaderSection.MinWidth := length(HeaderSection.Text) * Font.Size;
    // Owner draw every other section
    if (I mod 2 = 0) then
      HeaderSection.Style := hsOwnerDraw
    else
      HeaderSection.Style := hsText;
  end;
end;

procedure TForm1.HeaderControl1DrawSection(HeaderControl: THeaderControl;
  Section: THeaderSection; const Rect: TRect; Pressed: Boolean);
begin
  with HeaderControl.Canvas do
  begin
    // highlight pressed sections
    if Pressed then
      Font.Color := clRed
    else
      Font.Color := clBlue;
    TextOut(Rect.Left + Font.Size, Rect.Top + 2, 'Owner Drawn text');
  end;
end;

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!