Solved

datagridview c# reorder columns on bind

Posted on 2008-06-09
8
1,472 Views
Last Modified: 2012-06-22
My columns are correct in the designer.  when I bind to my ds, they are getting reordered. What is going on?
0
Comment
Question by:jackjohnson44
  • 3
  • 3
8 Comments
 
LVL 14

Expert Comment

by:Daniel Junges
Comment Utility
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
 

Author Comment

by:jackjohnson44
Comment Utility
I am creating the columns in the designer and binding at run time, not in the designer.
0
 
LVL 14

Accepted Solution

by:
Daniel Junges earned 500 total points
Comment Utility
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:jackjohnson44
Comment Utility
Isn't there a way to stop that from happening?  I thought that there was a flag that you could set or something.
0
 
LVL 14

Expert Comment

by:Daniel Junges
Comment Utility
I have posted a solution on this thread. I mean admins cannot simply delete solved questions .....
regards
junges
0
 

Author Closing Comment

by:jackjohnson44
Comment Utility
sorry for the delay, I just moved and did not have an internet connection for weeks
0
 
LVL 2

Expert Comment

by:sriraj2000
Comment Utility
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

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now