RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TCustomDrawGrid.OnRowMoved Event

Occurs immediately after the position of a row changes.

Pascal
property OnRowMoved: TMovedEvent;
C++
__property TMovedEvent OnRowMoved;

Write an OnRowMoved event handler to provide special processing whenever a row in the grid changes position. Rows can be moved programmatically or by user manipulation. OnRowMoved does not occur unless the Options property includes goRowMoving.  

C++ Examples: 

 

/*
The following code displays the number of rows a row was
moved in the first cell of the row.  To move rows in a
TStringGrid, goRowMoving must be included in the Options property.
*/
void __fastcall TForm1::StringGrid1RowMoved(TObject *Sender, int FromIndex, int ToIndex)

{
  int delta = (FromIndex > ToIndex) ? (FromIndex-ToIndex) : (ToIndex-FromIndex);
  StringGrid1->Cells[0][ToIndex] = IntToStr(delta);
}

void __fastcall TForm1::FormCreate(TObject *Sender)
{
  StringGrid1->Cells[2][0] = "Phone Number";
  StringGrid1->Cells[2][1] = "(408)984-1234";
  StringGrid1->Cells[2][2] = "(415)434-6789";
  StringGrid1->Cells[2][3] = "(650)696-2345";
  StringGrid1->Cells[2][4] = "(831)431-2422";
  StringGrid1->Cells[2][5] = "(408)506-9876";
  StringGrid1->Cells[1][0] = "Name";
  StringGrid1->Cells[1][1] = "Clem Myers";
  StringGrid1->Cells[1][2] = "Ed Satchel";
  StringGrid1->Cells[1][3] = "Johanna Mills";
  StringGrid1->Cells[1][4] = "Stella Gables";
  StringGrid1->Cells[1][5] = "Ted Thompson";
  StringGrid1->Cells[3][0] = "POB";
  StringGrid1->Cells[3][1] = "Detroit";
  StringGrid1->Cells[3][2] = "Memphis";
  StringGrid1->Cells[3][3] = "New Orleans";
  StringGrid1->Cells[3][4] = "Lander";
  StringGrid1->Cells[3][5] = "Round Pond";
  StringGrid1->Cells[4][0] = "State";
  StringGrid1->Cells[4][1] = "Michigan";
  StringGrid1->Cells[4][2] = "Tennessee";
  StringGrid1->Cells[4][3] = "Lousiana";
  StringGrid1->Cells[4][4] = "Wyoming";
  StringGrid1->Cells[4][5] = "Maine";
  StringGrid1->Cells[5][0] = "Last Graduated";
  StringGrid1->Cells[5][1] = "Michigan State";
  StringGrid1->Cells[5][2] = "Univ-> Colorado";
  StringGrid1->Cells[5][3] = "Univ-> Washington";
  StringGrid1->Cells[5][4] = "USC";
  StringGrid1->Cells[5][5] = "Bowdoin";
}

 

Delphi Examples: 

{
The following code displays the number of rows a row was
moved in a label.  To move rows in a TStringGrid, goRowMoving
must be included in the Options property.
}
procedure TForm1.StringGrid1RowMoved(Sender: TObject; FromIndex, ToIndex: Longint);
begin
  Label1.Caption := IntToStr(Abs(FromIndex-ToIndex));
end;

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!