Solved

Arranging DBGrid Columns

Posted on 2008-10-29
2
224 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Accepted Solution

by:
geocoins-software earned 0 total points
ID: 22831772
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
ID: 22855688
If you solved it, please ask that this Q be closed. You can click the delete link.

John
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Simple Delphi Question 9 106
How to renew a Delphi rad-studio licence? 5 77
Is anyone willing to have a look through this code and help debug? 25 93
Delphi...Split view - idea? 1 117
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

696 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