Groups | Blog | Home
all groups > dotnet windows forms databinding > december 2005 >

dotnet windows forms databinding : binding does not work if control is not displayed


rushabh_subscriptions NO[at]SPAM dadbhawala.in
12/19/2005 7:35:40 PM
Suppose:

* I have a class Name with two properties: FirstName, LastName. Both
string.

* I have a form with one TabControl with 2 TabPages, with one TextBox
on each TabPage.

* I bind an instance of the Name class on the Form's Load event. For
each Binding object (one for each TextBox), I set the UpdateModes for
both DataSource and Control to "Never" as I want the user to explicity
click a "Save" button when he's ready to commit the information.

Result of running this Form:

* The TextBox of the visible TabPage gets bound very well, and displays
the property value. BUT, the TextBox of the second TabPage remains
blank.

Problem:

* The property value should have been set in all the TextBoxes, but
this does not happen for the ones which are not immediately rendered.

Possible Cause:

* The only difference is that one TextBox is going to get displayed /
rendered / drawn on Load, while the other gets displayed / rendered /
drawn later.

* DataSourceUpdateMode and ControlUpdateMode are set to "Never". If
they remain as their default values, things work fine, but that is not
my requirement.

* Because the DataSourceUpdateMode and the ControlUpdateMode have been
set to "Never", the value which should pass from the DataSource to the
Control, does not pass when the Control gets activated / created /
selected.

Can somebody provide with a solution ?

Requirements:

* The Form Controls have been split across multiple TabPages in the
TabControl.

* DataSourceUpdateMode and ControlUpdateMode are set to "Never" for all
the Bindings between the object and the controls.


regards,
RD
Ron Dahl
1/11/2006 1:43:56 AM
You are not alone with this problem.

My workaround was to show the form and then to activate each tab page and
then close the form.

On most computers the screen updating wasn't terribly distracting, but I
know my work around is not the ideal solution.

Ron Dahl


[quoted text, click to view]

RD
1/16/2006 7:39:26 PM
Ron:

I have devised a different solution. I leave the Control Update mode to
its default value. As a result, all the values get displayed correctly
in the controls.

But the DataSource gets updated only when I call WriteValue(). But the
problem here is that when value from the first control is written to the
DataSource, values from all other properties of the DataSource are read
into the Controls. As a result, all the changes that I have made in
other controls are lost.

What I do is store the ControlUpdateMode and the DataSourceUpdateMode
for all Controls in a Hashtable, set these properties to "Never", then
call WriteValue on all the bindings, and reset these properties back to
their original values.

Not a great solution, but solves the problem.

- RD.


[quoted text, click to view]


--
Sent via .NET Newsgroups
AddThis Social Bookmark Button