Solved

Arranging DBGrid Columns

Posted on 2008-10-29
2
223 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
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Send message from delphi to whatsapp, is it possible? 3 1,641
Reconfigure Delphi Install? 2 60
How to convert memory stream to PDF file 6 103
RESTRequest Parameter 4 41
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

792 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