ClientDataSetMoveBy (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

The following example enables you to move the current selected cell in a db grid. The Up and Down buttons have their OnClick events assigned to the UpDownClick procedure. The Left and Right buttons have their OnClick events assigned to the LeftRightClick procedure. The Up and Left buttons have their Tag property set to -1, while the Down and Right buttons have their Tag property set to 1. MoveBy does not move the cell in the db grid, it only moves the selection. The dataset is not edited. Notice that the Up button and the Down button are separate TButtons, not one TUpDown. The tags must be set as different.

Code

procedure TForm1.UpDownClick(Sender: TObject);
begin
  CDS.MoveBy(TComponent(Sender).Tag);
  DBGrid1.SetFocus;
end;

procedure TForm1.LeftRightClick(Sender: TObject);
begin
  DBGrid1.SelectedIndex := DBGrid1.SelectedIndex + TComponent(Sender).Tag;
  DBGrid1.SetFocus;
end;

Uses

See Also

Personal tools
Assistance