Databinding is late!

G

Guest

The controls in my form are bounded to a datasource, including textboxes,
comboboxes, etc...
Something lame happens: In runtime, the last focused control before clicking
on my save button, doesn't have its datasource bounded value refreshed with
the new data inputed. I think the control's LostFocus event it's not properly
fired when I click a ToolStrip button, and the databinding is not updated.

I came with the following piece of code on the Save function to solve this
problem:

if (this.ActiveControl != null && (this.ActiveControl is TextBox ||
this.ActiveControl is ComboBox || this.ActiveControl is MaskedTextBox))
this.ActiveControl.DataBindings[0].WriteValue();

It works fine. I just wonder if there's a better and cleaner way to solve my
problem; a property or something.

Thanks and happy chrtistmas.
 
M

MuZZy

Bruno said:
The controls in my form are bounded to a datasource, including textboxes,
comboboxes, etc...
Something lame happens: In runtime, the last focused control before clicking
on my save button, doesn't have its datasource bounded value refreshed with
the new data inputed. I think the control's LostFocus event it's not properly
fired when I click a ToolStrip button, and the databinding is not updated.

I came with the following piece of code on the Save function to solve this
problem:

if (this.ActiveControl != null && (this.ActiveControl is TextBox ||
this.ActiveControl is ComboBox || this.ActiveControl is MaskedTextBox))
this.ActiveControl.DataBindings[0].WriteValue();

It works fine. I just wonder if there's a better and cleaner way to solve my
problem; a property or something.

Thanks and happy chrtistmas.

We had the same problem with our application... Our solution was to call
Form.SelectNextControl as it applies a value when leaves the control

I know, not a clean one but i didn't find anything better. Unfortunately
..NET's binding mechanism sucks badly :(

MuZZy
 
M

MuZZy

Bruno said:
The controls in my form are bounded to a datasource, including textboxes,
comboboxes, etc...
Something lame happens: In runtime, the last focused control before clicking
on my save button, doesn't have its datasource bounded value refreshed with
the new data inputed. I think the control's LostFocus event it's not properly
fired when I click a ToolStrip button, and the databinding is not updated.

I came with the following piece of code on the Save function to solve this
problem:

if (this.ActiveControl != null && (this.ActiveControl is TextBox ||
this.ActiveControl is ComboBox || this.ActiveControl is MaskedTextBox))
this.ActiveControl.DataBindings[0].WriteValue();

It works fine. I just wonder if there's a better and cleaner way to solve my
problem; a property or something.

Thanks and happy chrtistmas.

By the way, in my app i came across another stupid issue with bindings -
if you have a bound text box and it's active control on the form, and
you activate another form, then go back to the first form and type
something in that active text box, it looses binding, i.e. whaterver you
type in it will no longer go to the dataset.

The workaround i found was to reactivate the text control when form
becomes active again:

void form_Activate(...)
{
form.ActiveControl = null;
form.ActiveControl = textBox1;
}
 

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