Data Combo Box
Data Combo Box
.DataSource = dvProducts
.DisplayMember = "ProductName"
.ValueMember = "ProductID"
End With
ComboBox1.SelectedIndex = 0
lblDataSource.Text = "DataView"
lblAssocValue.Text = ComboBox1.SelectedValue.ToString
End Sub
''' <summary>
''' Bind to the BindingSource that binds to the NorthwindDataset Products table.
''' </summary>
Private Sub btnDC_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDC.Click
With ComboBox1
.DataSource = Me.ProductsBindingSource
.DisplayMember = "ProductName"
.ValueMember = "ProductID"
End With
ComboBox1.SelectedIndex = 0
lblDataSource.Text = "BindingSource"
lblAssocValue.Text = ComboBox1.SelectedValue.ToString
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles
ComboBox1.SelectedIndexChanged
' Display the associated value for the item selected from the combox,
' if one is available. To determine a value is available
' check the visibility of the groupbox. This attribute has been set to false
' during binding by code if a value is not available, to true if it is.
If Me.ComboBox1.SelectedIndex >= 0 Then
lblAssocValue.Text = ComboBox1.SelectedValue.ToString
Else
lblAssocValue.Text = "Nothing selected"
End If
End Sub
Private Sub exitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles exitToolStripMenuItem.Click
Me.Close()
End Sub
Private Sub ProductsBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ProductsBindingNavigatorSaveItem.Click
Me.Validate()
Me.ProductsBindingSource.EndEdit()
Me.ProductsTableAdapter.Update(Me.NorthwindDataSet.Products)
End Sub
End Class