Bind CheckBox to a bool - not a dataset, just a bool

S

sklett

I can't find an example of how to bind a bool to a CheckBox.
DataBindings.Add() takes 3 parameters;
1) the name of the bound property
2) the data source
3) the name of the data source property.

In the case of a simple bool... what is the data source property name?

Here is what I'm after:
bool someBool = false;
checkBox1.DataBindings.Add("checked", someBool, ????);

Thanks for any help,
Steve
 
E

Eugene

private bool someBool = false;
public bool BoolProperty{
get{
return someBool;
}
set{
someBool = value;
}
}

this.checkBox1.DataBindings.Add("Checked",this,"BoolProperty");

Change your mind to fix the issue.
±äͨһϾͿÉÒÔ½â¾öÎÊÌâ

Eugene
 
S

sklett

ah, so it needs to be bound to a property! Makes sense.

Thanks for the help,
Steve
 
B

Bruce Wood

I'm not up to speed on my .NET 2.0 bindings, but I believe that if you
want it to be a two-way binding (that is, a change to the bool
property causes the CheckBox to change its state) then there must be
some sort of event or something to signal the binding that the bool
property's value has changed, no?

Certainly a one-way binding (changes in check box cause changes in
bool property) doesn't need this, but a two-way binding would.
 
?

=?ISO-8859-1?Q?Christian_K=F6nig?=

You have to implement the INotifyPropertyChanged interface.
The documentation on this Topic is real good :).

Christian

Sorry for any errors in my english :-(
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top