Solved

Arranging DBGrid Columns

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

770 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