Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / December 2005

Tip: Looking for answers? Try searching our database.

Databinding is late!

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bruno Rodrigues - 23 Dec 2005 12:53 GMT
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.
MuZZy - 23 Dec 2005 15:53 GMT
> The controls in my form are bounded to a datasource, including textboxes,
> comboboxes, etc...
[quoted text clipped - 14 lines]
>
> 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
MuZZy - 23 Dec 2005 15:57 GMT
> The controls in my form are bounded to a datasource, including textboxes,
> comboboxes, etc...
[quoted text clipped - 14 lines]
>
> 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;
}

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.