Move Columns in a TDBGrid

Submitted by:J Kamy81

Date added:06 October, 2019

Category:Delphi

Delphi code example to move columns in a TDBGrid

Tags: move columns , tdbgrid

Code Snippet:


type
THackAccess = class(TCustomGrid);

{
THackAccess Is needed because TCustomGrid.MoveColumn is
protected and you can't access it directly.

THackAccess Braucht man, da TCustomGrid.MoveColumn in der
Protected-Sektion steht und nicht direkt darauf zugegriffen werden kann.
}

// In the implementation-Section:

procedure MoveDBGridColumns(DBGrid: TDBGrid; FromColumn, ToColumn: Integer);
begin
THackAccess(DBGrid).MoveColumn(FromColumn, ToColumn);
end;


{Example/ Beispiel}

procedure TForm1.Button1Click(Sender: TObject);
begin
MoveDBGridColumns(DBGrid1, 1, 2)
end;
 
 

Comments