Solved

datagridview c# reorder columns on bind

Posted on 2008-06-09
8
1,481 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
8 Comments
 
LVL 14

Expert Comment

by:Daniel Junges
ID: 21745568
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
ID: 21745647
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
ID: 21745719
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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

Author Comment

by:jackjohnson44
ID: 21752886
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
ID: 22002576
I have posted a solution on this thread. I mean admins cannot simply delete solved questions .....
regards
junges
0
 

Author Closing Comment

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

Expert Comment

by:sriraj2000
ID: 26039654
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

737 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