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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Databound Checkboxes

Status
Not open for further replies.

abcfantasy

Programmer
Jun 3, 2006
110
DK
I've got a few checkboxes databound to a bindingsource. When I create a new record, their checked state changes to indeterminate. How can I change it to make it unchecked or checked by default?

I tried to add a piece of code after the Add New button has been clicked, which sets the checkedboxes state to unchecked but it doesn't work.

Any help is appreciated
Thanks
Andrew

ABC -
 
are you setting the unchecked code before or after you data bind?
 
Not sure about this. I created the data binding in the IDE, then set the checked state exactly after calling myBindingSource.AddNew() method.

ABC -
 
this one had me buzzing about for weeks.

if you change a value from code, binding will only copy data from the datasource to the control.
only user input will cause the data to be copied the other way.

so change the object on the datasource, and not the control.

hth,


mr s. <;)

 
Sorry what did you mean by the object on the datasource?

But in any case, I solved it by setting the default values using the dataset designer (.xsd).

Thanks for your help

ABC -
 
eg: checkBox1.Checked is bound to boolean column TheTable.BoolColumn.

if you change checkBox1.Checked from code the binding will ignore the change.

you have to change the value of thing it's bound to, in this case the value held in the column on the database, and the binding will take care of updating the control.

hope this helps.



mr s. <;)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top