all groups > dotnet windows forms databinding > september 2006 >
You're in the

dotnet windows forms databinding

group:

UserContol and DataBinding


UserContol and DataBinding Kyle Jedrusiak
9/13/2006 4:14:45 PM
dotnet windows forms databinding:
On a form we have a TextBox. It's Text property is data bound to a field in
a data source.

When you get the data from the database, the TextBox shows the data
properly.

When you change the text and then hit tab, the changes are written back to
the bound field.


We have a UserControl named MonthYearPicker with a r/w property named
SelectedDate.

We place that on a form. It's SelectedDate property is data bound to a
field in a data source.

When you get the data from the database, the MonthYearPicker displays the
data properly.

When you change the month or the year or both and hit tab, the changes ARE
NOT written back to the bound field.

Caveat...if you then click in the TextBox and hit tab, the changes for the
MonthYearPicker get written to the bound field.


So something about our UserControl it's letting the DataBinding know that
the data on the control has changed.

It also seems to happen with CheckBox controls as well.

Can someone point me in the right direction on this.

Thanks

Kyle!

Re: UserContol and DataBinding Bart Mermuys
9/17/2006 7:08:04 PM
Hi,

[quoted text, click to view]

If your UserControl also has a SelectedDateChanged *event* (typeof
EventHandler) then that event informs databinding the value has changed, if
it doesn't have such an event then the value is always considered changed.
The (changed) value is persisted to the underlying data source (field) when
the Control's Validating event is fired. So the first thing would be to
check if the Validating event is fired properly.

[quoted text, click to view]

Also make sure you're not binding (default) null value's to CheckBox (or
other Controls that don't support null values).

---
HTH,
Greetings

[quoted text, click to view]

AddThis Social Bookmark Button