Groups | Blog | Home
all groups > dotnet windows forms databinding > september 2005 >

dotnet windows forms databinding : databinding to two comboboxes through dataset relationship



Robin
9/14/2005 3:59:03 PM
I have two combo boxes that are populated and bound from two related dataset
tables through their relationship, like this:

//bind to domain tables to populate values
ParentComboBox.DataSource = myDataSet.ParentTable;
ParentComboBox.DisplayMember = "Name";
ParentComboBox.ValueMember = "NameID";

ChildComboBox.DataSource = myDataSet.ParentTable;
ChildComboBox.DisplayMember = "ChildParentRelationship.ChildName";
ChildComboBox.ValueMember = "ChildParentRelationship.ChildNameID";

//bind to a different dataset table where value will be saved...
ParentComboBox.DataBindings.Add("SelectedValue", _dataSource, _dataMember +
".ParentID");
ChildComboBox.DataBindings.Add("SelectedValue", _dataSource, _dataMember +
".ChildID");


This code automatically filters the second (child) combo box when the parent
combo box value is changed, because of the dataset relationship. The problem
is that, the child value does not get saved or even recognized through
binding. I can't even endcurrentedit manually, but no event gets fired when
the second combo box changes through this binding method (ValueMemberChanged
for example).

The value of the second combo box only saves when you manually select it. The
user would need to manually select a value from the second combobox every
time, even if the correct one is shown when the parent combo box is changed.
Please provide a solution. thanks.

v-jetan NO[at]SPAM online.microsoft.com (
10/5/2005 7:55:08 AM
Hi robinne123,

Thanks for your post.

No, I do not think we can save the selected value in combobox in this way.
Because the ComboBox.SelectedValue is populated by complex databinding, we
can not use another simple databinding to save it value in another
datasource.

To save the selected value, we can hook ComboBox's SelectedIndexChanged
event and save the current selected value in this event.

Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
AddThis Social Bookmark Button