?
Solved

datagridview c# reorder columns on bind

Posted on 2008-06-09
8
Medium Priority
?
1,483 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 2000 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
AWS Certified Solutions Architect - Associate

This course has been developed to provide you with the requisite knowledge to not only pass the AWS CSA certification exam but also gain the hands-on experience required to become a qualified AWS Solutions architect working in a real-world environment.

 

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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
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!
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

764 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