Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataBindings problem

Status
Not open for further replies.

mustangman96

Programmer
Apr 23, 2003
14
HU
How can I bind my checkbox control to a dataset?
I use sqlDataAdapter to generate the dataset.

The SQL column type is "bit" and allows nulls. Name is: "active".

This works fine with a textBox:
Code:
this.mytextBox.DataBindings.Add("Text",this.dsMyDataSet.partners,"name");

But this doesn't work with my checkBox:
Code:
this.mycheckBox.DataBindings.Add("Checked",this.dsMyDataSet.partners,"active");

The code runs and when I click on the dataGrid the following error raises:

"DataBinding could not find a row in the list that is suitable for all bindings"
 
If you bind a grid with a DataTable which contains the bit columns then you have only to do like here and all the bit columns will be shown as checkbox with the right value from the table:
// Here is the categories table which have 2 bit columns:
this.oleDbConnection1.Open();
dt = new DataTable();
this.oleDbSelectCommand1.CommandText="Select * from Categories";
this.oleDbDataAdapter1.Fill(dt);
this.dataGrid1.SetDataBinding(dt,"");

This is the simplest example but in real project/applications there is more work to do when binding a grid and update the source data.

-obislavu-
 
Obislavu, thank you for your help, but that wasn't really the answer to my problem.

If anyone interested the solution was:

I have to set the DefaultValue property of the column before the datagrid.datasource property gets the dataset.

Code:
this.dsMyDataSet.partners.activeColumn.DefaultValue=false;
this.dataGrid1.DataSource=this.dsMyDataSet.partners;

Now it works!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top