Multiple combo boxes bound to the same datatable

  • Thread starter Thread starter Young J. Putt
  • Start date Start date
Y

Young J. Putt

I have what I thought was a relatively simple data situation that I can't
seem to get working using ADO.NET datasets and data binding.
I have an "Issues" table which records the UserID of the user that opens,
closes and is assigned to the Issue. These come from the same group of
users, so they are all related to a "Users" table. I have three combo boxes
on a form. I set up the binding as shown below. It works when the form is
loaded, but when I change one of the combo boxes, they all change. Based on
what I've read, I believe I need a different BindingManagerBase for each
combo box, but I've been unable to find an example of how to actually do
this. Can anyone help?

'Closed By
cboClosedBy.DataSource = dsAppData.Tables("Users")
cboClosedBy.DisplayMember = "UserName"
cboClosedBy.ValueMember = "UserID"
cboClosedBy.DataBindings.Add("SelectedValue", dvIssue, "ClosedBy")
'Opened By
cboOpendBy.DataSource = dsAppData.Tables("Users")
cboOpendBy.DisplayMember = "UserName"
cboOpendBy.ValueMember = "UserID"
cboOpendBy.DataBindings.Add("SelectedValue", dvIssue, "OpenedBy")
'Assigned To
cboAssignedTo.DataSource = dsAppData.Tables("Users")
cboAssignedTo.DisplayMember = "UserName"
cboAssignedTo.ValueMember = "UserID"
cboAssignedTo.DataBindings.Add("SelectedValue", dvIssue, "AssignedTo")
 
You need multiple BindingContexts. By default, all controls bound to the
same source share a BM.

A control has a BindingContext property. Simply do something like this:
me.control.bindingcontext = new bindingcontext.
 
That was all I needed! Thank you!



Greg said:
You need multiple BindingContexts. By default, all controls bound to the
same source share a BM.

A control has a BindingContext property. Simply do something like this:
me.control.bindingcontext = new bindingcontext.
 
An other alternative I always use is have a dataview for each item. The
dataviews are bound to the same table and each combobox is bound to a
different dataview. This gives a unique binding context for every control.

Guillaume Hanique.
 
Back
Top