TcxGridTableView.OnColumnHeaderClick Event
Allows you to respond to a click on a column header.
Declaration
property OnColumnHeaderClick: TcxGridColumnEvent read; write;
Remarks
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:
- The OptionsCustomize.ColumnSorting property is set to
True
(default). - The target column’s Options.Sorting property is set to
True
(default).
You can handle the OnColumnHeaderClick
event to execute custom code when a user clicks a column header.
Event Occurrence
The OnColumnHeaderClick
event occurs every time a user clicks a column header.
Event Parameters
The following parameters are available within an OnColumnHeaderClick
event handler:
Sender
- Provides access to the grid Table View that raised the column header click events.
AColumn
- Provides 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.
Code Example: Identify the Dataset Field Name of the Clicked Column
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; // This unit 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;