Link to home
Start Free TrialLog in
Avatar of geocoins-software
geocoins-software

asked on

Arranging DBGrid Columns

I have a DBGrid on a form. Above it, I have a Listbox with the DBGrid's Column names listed.

To the right, I have an Up & Down button. (See code Below). These buttons allow me to change the order of the column names in the listbox.

I would also like to change the order of the DBGrid's Columns as well.

So, when I click the Up button. As the code shows, it will exchange the listbox item with the previous one. I need it to also change the actual Grids Column as well.

Same thing for Down button


thanks
procedure TfrmOptions.btnUpClick(Sender: TObject);
begin
 lbxColumns.Items.Exchange(lbxColumns.ItemIndex, lbxColumns.ItemIndex-1);
 lbxColumns.ItemIndex:= lbxColumns.ItemIndex - 1;
end;
 
procedure TfrmOptions.btnDownClick(Sender: TObject);
begin
 lbxColumns.Items.Exchange(lbxColumns.ItemIndex, lbxColumns.ItemIndex+1);
 lbxColumns.ItemIndex:= lbxColumns.ItemIndex + 1;
end;

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of geocoins-software
geocoins-software

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you solved it, please ask that this Q be closed. You can click the delete link.

John