Databinding w/Update

G

Guest

Hi All,

I am under the impression that databinding allows a control to be updated
automatically by the interface when the underlying value changes. However,
many of my controls will not update after the initial display. If I have a
boolean property and I bind it to a checkbox's checked property, I should be
able to change the boolean from true to false and observe the checkbox go
from checked to unchecked. Is there something else I should be doing or am I
totally off-base?
 
N

Norman Yuan

Are you talking about Win Form App? If yes, showing some code may help to
see what happens.
 
P

Peter Huang [MSFT]

Hi Harry,

Here is some code for your reference.
private bool bChecked;
public bool MyChecked
{
set{bChecked = value;}
get{return bChecked;}
}
private void Form1_Load(object sender, System.EventArgs e)
{
this.DataBindings.Add("MyChecked",this.checkBox1,"Checked");
this.checkBox1.CheckedChanged+=new
EventHandler(checkBox1_CheckedChanged);
}

private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
this.Text = MyChecked.ToString();
}

Also here is a link you may take a look.
http://groups.google.co.jp/groups?hl=zh-CN&lr=&threadm=1d438033.0404210520.2
5a73e87%40posting.google.com&rnum=5&prev=/groups%3Fhl%3Dzh-CN%26lr%3D%26q%3D
%2522checkBox1.DataBindings.Add%2522


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
D

Dmytro Lapshyn [MVP]

Hi Harry,

For the databinding to work properly, each bindable property on a class or
on a component must be complemented with an event of type EventHandler. This
event must be named <Property>Changed, where <Property> is the name of your
property. E.g. if your property is named IsAvailable, the event must be
named IsAvailableChanged.

This applies if your properties are real properties and not 'virtual' ones
exposed through ICustomTypeDescriptor.
 
G

Guest

I have the same problem and can't figure out what to do.
I have a window application with a textbox(VS2003). I set the databinding
property, text, of the textbox to one of the column of the dataset.
I assume when I change the textbox value, it will update the column of the
table automatically. When it does not update the table, I added code in the
textchange method of the textbox to do an update, such as:
oleDBDataAdapter1.Update(dataSet1);
and it still does not update the table.
Does anyone have any clue how to make this work?

Dmytro Lapshyn said:
Hi Harry,

For the databinding to work properly, each bindable property on a class or
on a component must be complemented with an event of type EventHandler. This
event must be named <Property>Changed, where <Property> is the name of your
property. E.g. if your property is named IsAvailable, the event must be
named IsAvailableChanged.

This applies if your properties are real properties and not 'virtual' ones
exposed through ICustomTypeDescriptor.
 

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