I want my combo boxes to change based on the what is selected on my datagridview.
What I've tried:
Private Sub MyDataGridView_SelectionChanged2(sender As Object, e As EventArgs) Handles DataGridView2.SelectionChanged
With DataGridView2
If .SelectedRows IsNot Nothing AndAlso .SelectedRows.Count = 1 Then
Dim row As DataGridViewRow = .SelectedRows(0)
Form2.ComboBox1.Text = row.Cells(5).Value.ToString()
Form2.ComboBox2.Text = row.Cells(6).Value.ToString()
Form2.ComboBox3.Text = row.Cells(7).Value.ToString()
Form2.ComboBox4.Text = row.Cells(8).Value.ToString()
Form2.ComboBox5.Text = row.Cells(9).Value.ToString()
Form2.ComboBox6.Text = row.Cells(10).Value.ToString()
Form2.ComboBox7.Text = row.Cells(11).Value.ToString()
Form2.ComboBox8.Text = row.Cells(12).Value.ToString()
Form2.ComboBox9.Text = row.Cells(13).Value.ToString()
End If
End With
End Sub
This code has no effect, but I do feel that I am heading in the right direction.
On DataGridView2 properties go to SelectionMode and select FullRowSelected.
Or add this line code on the Form1_Load(sender As Object, e As EventArgs)
DataGridView2.SelectionMode = DataGridViewSelectionMode.FullRowSelect
If can also remove the ".SelectedRows IsNot Nothing AndAlso" because it will always have a value, even there is nothing selected it will return a Zero not a null.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.