471,618 Members | 1,077 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,618 software developers and data experts.

Databinding is late!

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.
Dec 23 '05 #1
2 2329
Bruno Rodrigues wrote:
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
Dec 23 '05 #2
Bruno Rodrigues wrote:
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;
}
Dec 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Steven | last post: by
2 posts views Thread by z. f. | last post: by
3 posts views Thread by Kevin Swanson | last post: by
13 posts views Thread by Michael Maes | last post: by
8 posts views Thread by GaryDean | last post: by
1 post views Thread by =?Utf-8?B?QWxoYW1icmEgRWlkb3MgS2lxdWVuZXQ=?= | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.