Back to Devexpress

TcxGridTableView.OnColumnHeaderClick Event

vcl-cxgridtableview-dot-tcxgridtableview-bf8c901c.md

latest3.7 KB
Original Source

TcxGridTableView.OnColumnHeaderClick Event

Allows you to respond to a click on a column header.

Declaration

delphi
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:

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:

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.

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.

delphi
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;
cpp
#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

TcxGridTableOptionsView.Header Property

TcxGridTableView Class

TcxGridTableView Members

cxGridTableView Unit