Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Two sets of columns
 

Two sets of columns

Idesigned the datagridview column headers using the IDE.

I then programatically connected the datagridview.datasource and column dataproperty names.

Code Snippet

//Set the DataAdapter with the Datatable

this.daTransactions.Fill(this.dtTransactions);

//Set the BindingSource with the datatable

this.bsTransactions.DataSource = this.dtTransactions;

//Bind the navigator to the grid

this.dgv.DataSource = this.bsTransactions;

//Set the columns

DataGridViewColumn column0 = this.dgv.Columns[0];

column0.DataPropertyName = "CARDNO";

When I run the program I get two sets of columns.

How would I correct this?

Can-Ann  Thursday, July 05, 2007 5:38 PM
Set AutoGenerateColumns property of the DataGridView to false before setting the DataSource for the DataGridView will avoid this problem. Something like this:

//Set the DataAdapter with the Datatable

this.daTransactions.Fill(this.dtTransactions);
this.dgv.AutoGenerateColumns = false;

//Set the BindingSource with the datatable

this.bsTransactions.DataSource = this.dtTransactions;

//Bind the navigator to the grid

this.dgv.DataSource = this.bsTransactions;

Zhi-Xin Ye  Friday, July 06, 2007 8:34 AM
Set AutoGenerateColumns property of the DataGridView to false before setting the DataSource for the DataGridView will avoid this problem. Something like this:

//Set the DataAdapter with the Datatable

this.daTransactions.Fill(this.dtTransactions);
this.dgv.AutoGenerateColumns = false;

//Set the BindingSource with the datatable

this.bsTransactions.DataSource = this.dtTransactions;

//Bind the navigator to the grid

this.dgv.DataSource = this.bsTransactions;

Zhi-Xin Ye  Friday, July 06, 2007 8:34 AM

You can use google to search for other answers

Custom Search

More Threads

• Sorting algorithm has a bug ?!?
• How To update four related tables using a TableAdapter
• BindingSource Filter and Changing Values
• Custom databinding
• Setting Default values for BOUND ComboBoxes
• Datagridview changing row background color
• refreshing a textbox
• Set/change row height of datagridview programmatically?
• databound controls not updating - confusion between Linq datacontext/table objects and ado.net dataset/table objects
• TreeGrid Control