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
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