vcl-cxgridtableview-dot-tcxgridtableview-bf8c901c.md
Allows you to respond to a click on a column header.
property OnColumnHeaderClick: TcxGridColumnEvent read; write;
The grid View displays column headers if the OptionsView.Header property is set to True. A click on a column header sorts data by the column or changes sort order if the following conditions are met:
True ( default ).True ( default ).You can handle the OnColumnHeaderClick event to execute custom code when a user clicks a column header.
The OnColumnHeaderClick event occurs every time a user clicks a column header.
The following parameters are available within an OnColumnHeaderClick event handler:
SenderProvides access to the grid Table View that raised the column header click events.AColumnProvides access to the grid column whose header was clicked.
Refer to the TcxGridColumnEvent procedural type description for detailed information on parameters accessible within an OnColumnHeaderClick event handler.
The code example in this section updates sorting information in the form caption every time a user clicks a column header in a bound grid Table View. The code example displays the name of the clicked column’s underlying dataset field.
uses
dxCore; // Declares soAscending, soDescending, and soNone values
// ...
procedure TMyForm.cxGrid1DBTableView1ColumnHeaderClick(Sender: TcxGridTableView;
AColumn: TcxGridColumn);
var
AFieldName: string;
begin
AFieldName := (AColumn as TcxGridDBColumn).DataBinding.FieldName;
if AColumn.SortOrder <> soNone then
Caption := 'Data is sorted by ' + AFieldName;
else
Caption := 'Data is unsorted';
if AColumn.SortOrder = soAscending then
Caption := Caption + ' in ascending order'
else if AColumn.SortOrder = soDescending then
Caption := Caption + ' in descending order';
end;
#include "dxCore.hpp" // Declares soAscending, soDescending, and soNone values
// ...
void __fastcall TMyForm::cxGrid1DBTableView1ColumnHeaderClick(TcxGridTableView *Sender,
TcxGridColumn *AColumn)
{
UnicodeString AFieldName;
// ...
AFieldName = dynamic_cast<TcxGridDBColumn*>(AColumn)->DataBinding->FieldName;
if(AColumn->SortOrder != soNone)
Caption = "Data is sorted by " + AFieldName;
else
Caption = "Data is unsorted";
if(AColumn->SortOrder == soAscending)
Caption = Caption + " in ascending order";
else if(AColumn->SortOrder == soDescending)
Caption = Caption + " in descending order";
}
See Also
TcxGridColumn.OnHeaderClick Event