Problem getting value from the DataGridView component?
How do I get the value from an selected row with the DataGridView component to an Label component?
How do I get the value from an selected row with the DataGridView component to an Label component?
If you've got full row select something like will make label1 = selectedrow column 2 (Remember its 0 based collection)
Label1.Text = DGV1.SelectedRows.Item(0).Cells(1).Value
With fullrow select then use the selectedcells collection instead.
I mean it should work like this no matter if I choose row 2 or row 5 or something else, it should show
the value automatic in the Label component.
Whatever cell/row you choose, then the label will show the value. What code have you tried? What events are you triggering off?
you can simply try in the CellEnter:
Label1.Text=DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value.ToString
This would work if you are using cell select and you are not allowing multiple cells to be selected (Multiselect property)
Example
Add a datagridview with a two columns.
Use this code.
At some text in the cells and then start chnaging the selections.
Public Class Form1
Private Sub DataGridView1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.SelectionChanged
Label1.Text = Me.DataGridView1.SelectedRows.Item(0).Cells(1).Value
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.DataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect
Me.DataGridView1.MultiSelect = False
End Sub
End Class