Button2的Click事件代码,目的,把DataGridView1第一列的数据添到ComboBox里面:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
For i = 1 To DataGridView1.RowCount - 1
ComboBox1.Items.Add(DataGridView1.Item(0, i).Value)
Next
End Sub
ComboBox的代码,目的:根据选择不同,改变TextBox文本显示
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim k As Integer
k = ComboBox1.SelectedIndex
If k < 0 Then Exit Sub
TextBox1.Text = DataGridView1.Item(2, k + 1).Value
End Sub
PS:ComboBox的选择项item从第0开始,DataGridView1的第0行为Head,你要的有效数据从第1开始。示例,如图