Recent

Author Topic: DBGrid move column a runtime  (Read 4326 times)

xinyiman

  • Hero Member
  • *****
  • Posts: 2261
    • Lazarus and Free Pascal italian community
DBGrid move column a runtime
« on: February 02, 2014, 01:35:37 pm »
Hello guys, who explains to me how I can move a column in a dbgrid at runtime?!

thank you very much
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: DBGrid move column a runtime
« Reply #1 on: February 02, 2014, 03:02:41 pm »
You could try this routine:

Code: [Select]
uses Grids, DBGrids;

procedure ExchangeColumns(aGrid: TDBGrid; index1, index2: integer);
var
  gcols: TGridColumns;
begin
  gcols:=aGrid.Columns;
  if not (gcols.HasIndex(index1) and gcols.HasIndex(index2))
    then Exit;
  gcols.BeginUpdate;
  gcols.Items[index2].Index:=index1;
  gcols.Items[Index1+1].Index:=index2;
  gcols.EndUpdate;
end;   

xinyiman

  • Hero Member
  • *****
  • Posts: 2261
    • Lazarus and Free Pascal italian community
Re: DBGrid move column a runtime
« Reply #2 on: February 02, 2014, 06:46:30 pm »
Perfect! Thank you  :)
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

 

TinyPortal © 2005-2018