Dual Combo box binding problem (relation involved)

  • Thread starter Thread starter Brian Henry
  • Start date Start date
B

Brian Henry

Here's an example of the code.. I have two combo boxes on screen that when
one's selection is change the other's items will be updated to reflect the
change (based on a relation)

Private ds_formData As New DataSet
'
' Fill Line Of Business
'
cmd_selectCommand.CommandText = "BENESP_GetLinesOfBusiness"
da_formData.FillSchema(ds_formData, SchemaType.Source, "LinesOfBusiness")
da_formData.Fill(ds_formData, "LinesOfBusiness")
'
' Fill in available types
'
cmd_selectCommand.CommandText = "BENESP_GetCoverageTypes"
da_formData.Fill(ds_formData, "CoverageTypes")

'///// Parts of that code is obviously missing, but thats just showing the
data being filled into the dataset (these are static lists and will never
change)
' Create relations
ds_formData.Relations.Add("LOBJunCoverageTypes",
ds_formData.Tables("LinesOfBusiness").Columns("LineOfBusinessID"),
ds_formData.Tables("CoverageTypes").Columns("LineOfBusinessID"))

'

' Set up combo box relation bindings

'

Me.cboCoverageLine.DataSource =
ds_formData.Relations("LOBJunCoverageTypes").ParentTable

Me.cboCoverageType.DisplayMember = "Name"

' Me.cboCoverageType.ValueMember = "CoverageTypeID"

Me.cboCoverageLine.ValueMember = "LineOfBusinessID"

Me.cboCoverageLine.DisplayMember = "Name"



Private Sub cboCoverageLine_SelectedValueChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles cboCoverageLine.SelectedValueChanged

If (Not Me.cboCoverageLine.SelectedValue Is Nothing) And (b_refillingData =
False) Then

Me.cboCoverageType.DataSource =
ds_formData.Tables("LinesOfBusiness").Rows.Find(Me.cboCoverageLine.SelectedV
alue).GetChildRows("LOBJunCoverageTypes")

Me.cboCoverageType.DisplayMember = "Name"

Me.cboCoverageType.ValueMember = "CoverageTypeID"



End If

End Sub





========================

now, when the user changes the comobo box, cbocoverageline it should update
the combo box cbocoveragetype with the related types tied to the selected
coverageline in the 1st combo box, well it gets the data back but the combo
box is instead of showing the data. it shows "System.Data.DataRow" the
correct number of items show up in the second combo box, but no name, just
the type of the object. How do i correct this? thanks
 
Brian:

If you have the relations set, just bind the second combo box to the dataset
or datatable. You don't need to do a find if the relations are in place
correctly.

That behavior is usually a sign that something isn't being resolved
correctly although the datasource is being set properly.
 
Hi William,

I tried before by setting the datasource of the 2nd combo box to the
childtable of the relation, and that didn't seem to work, can you give an
example of what you mean? thanks
 
Set it to the name of the bindingcontext.relation.

If you had a BindingContext with the name of employees bmb =
Me.BindingContext(Ds1, "Employees")

And a relation name relVisit
Dim relVisit As DataRelation
relVisit = New DataRelation("VisitRel", parentCol, vistaCol)

cbWhatever.ValueMember = "Employees.VistaRel"
 
I'm confused as to why I would set the value member to that when I'm not
trying to select an item, just reload a second combo box with all new data
that happens to be related to what is selected in the first combo box.
 
I have it working relatively easy using a data view, but thought using
relations would work somehow also
 
I forgot to include the displaymember. However, I noticed your next post
with the dataview, that's a pretty clean way to do it too.
 
Thanks for Bill's quick response!

Hi Brian,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that when you bind comboboxes to data
source, it displays System.Data.DataRow instead of Correct values. If there
is any misunderstanding, please feel free to let me know.

Generally, this might be caused by incorrect binding of data. Would you
please try to use typed DataSet instead. Because when using typed DataSet,
we can ensure that correct schema has been created, which makes binding
much more easier. Please also try to set binding properties in the
following order to make sure that there will be no excption thrown.

Me.cboCoverageLine.ValueMember = "LineOfBusinessID"
Me.cboCoverageLine.DisplayMember = "Name"
Me.cboCoverageLine.DataSource = ds_formData.Tables("LinesOfBusiness")

Me.cboCoverageType.DisplayMember = "Name"
' Me.cboCoverageType.ValueMember = "CoverageTypeID"

HTH. If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Back
Top