• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1486
  • Last Modified:

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?
0
jackjohnson44
Asked:
jackjohnson44
  • 3
  • 3
1 Solution
 
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
 
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
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
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

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!

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now