Solved

Arranging DBGrid Columns

Posted on 2008-10-29
2
219 Views
Last Modified: 2012-05-05
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

0
Comment
Question by:geocoins-software
2 Comments
 

Accepted Solution

by:
geocoins-software earned 0 total points
Comment Utility
SOLVED!

procedure TfrmOptions.btnUpClick(Sender: TObject);
begin
Grid.Columns.Items[lbxColumns.ItemIndex].Index := lbxColumns.ItemIndex - 1;
 lbxColumns.Items.Exchange(lbxColumns.ItemIndex, lbxColumns.ItemIndex-1);
 lbxColumns.ItemIndex:= lbxColumns.ItemIndex - 1;
end;
 
procedure TfrmOptions.btnDownClick(Sender: TObject);
begin
Grid.Columns.Items[lbxColumns.ItemIndex].Index := lbxColumns.ItemIndex + 1;
 lbxColumns.Items.Exchange(lbxColumns.ItemIndex, lbxColumns.ItemIndex+1);
 lbxColumns.ItemIndex:= lbxColumns.ItemIndex + 1;
end;
0
 
LVL 18

Expert Comment

by:Johnjces
Comment Utility
If you solved it, please ask that this Q be closed. You can click the delete link.

John
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This video discusses moving either the default database or any database to a new volume.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now