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 General / January 2007

Tip: Looking for answers? Try searching our database.

Binding to combo and checkbox not synching

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Flomo Togba Kwele - 29 Jan 2007 00:19 GMT
I have some comboxes and checkboxes on a UserControl, all of which are
bound to a BindingSource.

When I bound the bindingsource to the checkbox Checked property and
the user accepted the default (unchecked, false), the bindingsource
blew in the EndEdit event of the bindingsource on a null value for the
column in the dataset associated with the checkbox.

If I check the box and uncheck it before trying to save the row, the
error does not occur.

Similarly with the combos, if I select an item in the combobox at Load
time, it too gets the null error in the EndEdit event. The
bindingsource is bound to the combo's SelectedValue property. The
datasource of the combos are generic Lists of Strings, so I didn't
know what to place in the ValueMember's property.

I was forced to set the comboboxes SelectedIndex to -1 and bind the
checkboxes to the CheckedState property to force the user to change
state before saving.

There must be a better way to do this. Any suggestions?

Thanks
Linda Liu [MSFT] - 29 Jan 2007 08:08 GMT
Hi Flomo,

As for your first question:

Based on my understanding, you have a BindingSource component which has
been bound to a DataSet object. You bind the Checked property of a CheckBox
control to a field in the BindingSource component. When the user adds a new
row in the BindingSource and accept the default value (unchecked, false),
the value of the field in the BindingSource component remain null. If I'm
off base, please feel free to let me know.

It seems that the new row the user adds in the BindingSource has a null
value for the field. When the data source has either a value of Null or
False, the CheckBox control bound to the field has the Checked property of
the value of False. If the user doesn't change the CheckBox control's
checked state, data binding won't push the new value to the data source.
This behavior is by design.

To work around this problem, I suggest that you set the default value for
the field in the DataSet. To do this, open the DataSet in the designer by
double-clicking it in the Solution Explorer, and select the column in the
DataTable you want and set the column's DefaultValue property in the
Properties window.

As for your second question:

I performed a test based on your description. I set a ComboBox control's
the DataSource property to a List of strings(I didn't set its ValueMember
or DisplayMember), and bind its SelectedValue property to an other data
source. When the program is run, an exception occurs--'Cannot set the
SelectedValue in a ListControl with an empty ValueMember'.

In fact, in this scenario, we could bind the Text property of the ComboBox
control to the data source instead.

As for the problem of getting correct value in the data source after you
call the EndEdit method of the BindingSource component, ensure to set the
SelectedIndex/SelectedItem of the ComboBox AFTER it is bound to a data
source.

Hope this helps.
If you have anything unclear, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Linda Liu [MSFT] - 31 Jan 2007 10:15 GMT
Hi Flomo,

How about the problem now?

If the problem is still not solved and you need our further assistance,
please feel free to let me know.

Thank you for using our MSDN Managed Newsgroup Support Service!

Sincerely,
Linda Liu
Microsoft Online Community Support

Rate this thread:







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.