Board index » delphi » RX Tools DBGrid Button Click event

RX Tools DBGrid Button Click event

Does anyone know how to associated the Titlebutton event to the underlying
field in the table?  I want to sort the grid when the user clicks on the
Grid's Titlebar button.  I already know how sort a table and have found the
OnTitleBarClick event, I just don't know how to make sure it fires just for
the field clicked.

Thanks.

 

Re:RX Tools DBGrid Button Click event


Quote
"Jay Jackson" <jay.jack...@mci.NO_SPAM.com> wrote:
>Does anyone know how to associated the Titlebutton event to the underlying
>field in the table?  I want to sort the grid when the user clicks on the
>Grid's Titlebar button.  I already know how sort a table and have found the
>OnTitleBarClick event, I just don't know how to make sure it fires just for
>the field clicked.

Hi Jay.

Here's some code that'll do the trick.

procedure TForm1.RxDBGrid1TitleBtnClick(Sender: TObject; ACol: Integer;
  Field: TField);
begin
  try
    Table1.IndexFieldNames := Field.FieldName;
  except
  end;
end;   {Don't forget to set RxDBGrid.TitleButtons to TRUE}

Regards,
Chris Roberts

Re:RX Tools DBGrid Button Click event


Here are the two events I use with RxDbGrid (I got the code from the demos
that come with RxLib) :

This one will set the index (you don't have to worry which fields are
indexed)

procedure TfrmDeparts.dbGrdListeEmpTitleBtnClick(Sender: TObject+ADs-
  ACol: Integer+ADs- Field: TField)+ADs-
begin
  if TRxDBGrid(Sender).DataSource.DataSet is TTable then
  try
    TTable(TRxDBGrid(Sender).DataSource.DataSet).IndexFieldNames :+AD0-
      Field.FieldName+ADs-
  except
    TTable(TRxDBGrid(Sender).DataSource.DataSet).IndexFieldNames :+AD0- ''+ADs-
  end+ADs-
end+ADs-

This one will color the title button of the field by which the table is
sorted (I suppose you could change clInfoBk to clLime)

procedure TForm1.dbgrdBigGetBtnParams(Sender: TObject+ADs- Field: TField+ADs-
  AFont: TFont+ADs- var Background: TColor+ADs- IsDown: Boolean)+ADs-
begin
  if (TRxDBGrid(Sender).DataSource.DataSet is TTable) and (Field +ADwAPg- nil)
    and (Field.IsIndexField) then
     begin
       Background :+AD0- clInfoBk+ADs-
     end+ADs-
end+ADs-

Q

Jay Jackson a +AOk-crit dans le message +ADw-6g336k+ACQ-civ7+AEA-forums.borland.com+AD4-...
+AD4-Does anyone know how to associated the Titlebutton event to the underlying
+AD4-field in the table?  I want to sort the grid when the user clicks on the
+AD4-Grid's Titlebar button.  I already know how sort a table and have found the
+AD4-OnTitleBarClick event, I just don't know how to make sure it fires just for
+AD4-the field clicked.
+AD4-
+AD4-Thanks.
+AD4-
+AD4-

Other Threads