Solved

datagridview c# reorder columns on bind

Posted on 2008-06-09
8
1,482 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
Technology Partners: 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!

 

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

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 article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
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.

705 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