datagridview c# reorder columns on bind

My columns are correct in the designer.  when I bind to my ds, they are getting reordered. What is going on?
jackjohnson44Asked:
Who is Participating?
 
Daniel JungesCommented:
wen you bind at the runtime then the designed columns are lost. On bind at runtime the Columns are automatically redefined.

you can do the follow on you code:

DataGridViewColumn[] columns = new DataGridViewColumn[dataGridView1.Columns.Count];
 
dataGridView1.DataSource = ...;
dataGridView1.DataMember = ...;
 
dataGridView1.Columns.CopyTo( columns, 0 );
dataGridView1.Columns.Clear();
dataGridView1.Columns.AddRange(columns);

Open in new window

0
 
Daniel JungesCommented:
you have to add the dataset into you designer
- Set the datasource
- right click on the dataset and edit the columns

because you are binding it later then the columns from datagridview are redefined
0
 
jackjohnson44Author Commented:
I am creating the columns in the designer and binding at run time, not in the designer.
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
jackjohnson44Author Commented:
Isn't there a way to stop that from happening?  I thought that there was a flag that you could set or something.
0
 
Daniel JungesCommented:
I have posted a solution on this thread. I mean admins cannot simply delete solved questions .....
regards
junges
0
 
jackjohnson44Author Commented:
sorry for the delay, I just moved and did not have an internet connection for weeks
0
 
sriraj2000Commented:
This cannot be treated as the right solution unless the person who has questioned this has accepted this.  I have the same problem and I do not think that this is the solution for this.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.