-
Nov 30th, 2010, 12:09 PM
#1
Thread Starter
Frenzied Member
[RESOLVED] DataGridView Columns Order
Hello
I'm having a little problem with the order of the columns in the dgv.
I have a dgv with 5 columns (combos) added with the wizard, then in the form constructor i set the datasource, value member, displaymember and datapropertyname for each one, after this i fill the main data table and set the dgv datasource with it.
If i just do this and don't use the display index, the columns show in an wired order, doesn't show up like i defined in the wizard neither in the order of the sql statement.
For example, i add this columns (names):
B,C,E
Then if i use this select statement
Select A,B,C,D,E,F,G From Table
I thought that i can have one of this two situations, the columns that i added plus the remaining columns in the select or the columns in the order of the select. But that doesn't happen.
How the dgv choose the order of the columns?
Thanks
Rate People That Helped You
Mark Thread Resolved When Resolved
-
Nov 30th, 2010, 09:41 PM
#2
Re: DataGridView Columns Order
If you want a specific order then just set the DisplayIndex after binding.
-
Dec 1st, 2010, 10:52 AM
#3
Thread Starter
Frenzied Member
Re: DataGridView Columns Order
Thanks JMC
I know that (i wrote it in the post), i was just asking to know why the columns order don't respect any of the "orders"...
I'm testing only with a case where i have only 20 columns, but if i have for example 100, it's really annoying to set the display index for each one. If i know the order that the dgv puts the columns i could adapt the sql statement to simplify the code...
Rate People That Helped You
Mark Thread Resolved When Resolved
-
Feb 22nd, 2012, 07:54 AM
#4
Thread Starter
Frenzied Member
Re: DataGridView Columns Order
Using this old thread, just a little question...
I know if i add the columns using the wizard, or by code, before setting the datasource, the columns will be the first columns, and the original columns doesn't show up.
If i add the columns after setting the datasource i have the columns duplicated, the original and the new one, but in this case i have the correct indexes, but need to hide the original ones...
If i use the first approach in what event should I use to set the display index of the added columns?
Rate People That Helped You
Mark Thread Resolved When Resolved
-
Feb 22nd, 2012, 08:15 AM
#5
Re: DataGridView Columns Order
Perhaps I'm wrong but I believe that I have previously directed you to my CodeBank thread regarding adding a combo box column to a DataGridView. It demonstrates a grid with some columns added at design time and some added automatically at run time. It shows you what to do so just read it and do what it shows.
-
Feb 22nd, 2012, 09:35 AM
#6
Thread Starter
Frenzied Member
Re: DataGridView Columns Order
No you don't...
The "workaround" works fine when the columns in the datatable are in the order that you want to display them... if not I can do this and it looks like that it works:
vb.net Code:
DirectCast(DataGridView1.Columns("ColumnName"), DataGridViewColumn).DisplayIndex = DataGridView1.Columns.Count - 1
Just set the column to the end of the list...
Rate People That Helped You
Mark Thread Resolved When Resolved
-
Feb 22nd, 2012, 05:51 PM
#7
Re: [RESOLVED] DataGridView Columns Order
You do realise that there is more than one post in that thread, right? I demonstrate using the DisplayIndex to position columns, just as I said. It's there for those who care to read it.
-
Feb 22nd, 2012, 06:32 PM
#8
Thread Starter
Frenzied Member
Re: [RESOLVED] DataGridView Columns Order
Yes i read some of the posts, if it was the right thread... :S
The only info that i saw that matters for my problem it's int the #10... or i missed something!?
Thanks
Rate People That Helped You
Mark Thread Resolved When Resolved
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|