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 / Windows Forms / WinForm Data Binding / February 2006

Tip: Looking for answers? Try searching our database.

BindingSource.ResetBindings, the opposite way

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Maxwell2006 - 17 Feb 2006 02:18 GMT
Hi,

I understand that BindingSource.ResetBindings causes a control bound to the
BindingSource to reread all the items in the list and refresh their
displayed values.

The question is that how can I force the BindingSource to put controls' data
back to underlying data source?

Essentially, I want to do ResetBindings, but with opposite data flow (from
text box to data table)

Thank you,

Max
"Jeffrey Tan[MSFT]" - 17 Feb 2006 05:30 GMT
Hi Max,

Thanks for your post.

Based on my understanding, you want to push the modified control data into
the datasource.

First, I am not sure when you want to do this. .Net winform databinding is
a 2 way databinding, whenever you changed the control data, and when you
leave this control, winform databinding will automatically update the
datasource for you.

Second, I do not think the updating work can be controlled in BindingSource
class. The UI control should take charge of this. Can you show me which
control you want to do this?

Below is how to update the TextBox data to the datasource:
"4.22 I programatically change a bound TextBox value, but the value does
not get pushed back into the bound datasource. How can I make sure the
DataSource is updated?"
http://64.78.52.104/FAQ/WinForms/FAQ_c43c.asp#q1017q

Hope this helps!

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Signature

Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Bart Mermuys - 17 Feb 2006 11:55 GMT
Hi,

> Hi,
>
> I understand that BindingSource.ResetBindings causes a control bound to
> the BindingSource to reread all the items in the list and refresh their
> displayed values.

I agree with Jeffrey Tan that there probely aren't many reasons you need to
do this.   Expecially if your Control has changed then the last pending
change can be pushed using BindingSource.EndEdit().

But if you really want, you can (in NET2.0) force all values to be pushed to
the DataSource using:

foreach (Binding b in YourBindingSource.CurrencyManager.Bindings )
 b.WriteValue();

HTH,
Greetings

> The question is that how can I force the BindingSource to put controls'
> data back to underlying data source?
[quoted text clipped - 5 lines]
>
> Max
Maxwell2006 - 17 Feb 2006 14:58 GMT
Thank you Jeffrey and Bart for help.

Here is why you need to force data from control back to the underlying data:

Scenario 1) BindingSource is in AddNew mode and you have a DateTime picker
in your form. The datetime picker show a date value, but underlying data
will have NULL value even after EndEdit. I cannot tell user to click on
datetime picker and choose the same date value.

Scenario 2) Similar to scenario 1, but you are using a data bound drop down
combobox. ** combobox's DropDownStyle must be in DropDownList mode.

Your combobox has no item in it. You force the BindingSource to AddNew mode.
Then one items to combobox. The underlying data for combobox is still NULL!!

Essentially, When your BindingSource is in AddNew mode, and you have bound
controls that cannot show NULL values, then it involves all messes around
the world!!

Does that make any sense to you?

Max

> Hi,
>
[quoted text clipped - 11 lines]
>
> Max
Bart Mermuys - 17 Feb 2006 20:40 GMT
Hi,

> Thank you Jeffrey and Bart for help.
>
[quoted text clipped - 5 lines]
> will have NULL value even after EndEdit. I cannot tell user to click on
> datetime picker and choose the same date value.

AFAIK NULL value with a DateTimePicker may irreversible suspsend
DataBinding.  You should definitely set a default value for the Date fields,
you can do this by adding an eventhandler to DataTable.TableNewRow (which
will called when AddNew is called).  (Or find a nullable DateTimePicker)

> Scenario 2) Similar to scenario 1, but you are using a data bound drop
> down combobox. ** combobox's DropDownStyle must be in DropDownList mode.
>
> Your combobox has no item in it. You force the BindingSource to AddNew
> mode. Then one items to combobox. The underlying data for combobox is
> still NULL!!

If you mean adding ComboBox items to an empty ComboBox after AddNew, then i
can imagine this causes problems (but i haven't tried).  You could use
ComboBox.DataBindings["SelectedValue"].WriteValue() after filling the
ComboBox.

> Essentially, When your BindingSource is in AddNew mode, and you have bound
> controls that cannot show NULL values, then it involves all messes around
> the world!!
>
> Does that make any sense to you?

Sure, NULL values are a big problem with DataBinding, well mostly with the
Controls. There are 3th party or opensource Controls which can handle NULL
values better.

HTH,
Greetings

> Max
>
[quoted text clipped - 13 lines]
>>
>> Max

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.