I need to get the value of the next cell when one cell is clicked in vb.net.For example
ID | NAME | AGE
1 | Azleef | 20
2 | Saeed | 22
3 | Jimmy | 23
For example if I press Azleef I need the next cell. The corresponding age which is 20
You can get the functionality you want by relying on the CellClick event. Sample code for DataGridView1:
Private Sub DataGridView1_CellClick(sender As Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick If (e.ColumnIndex > -1 AndAlso e.RowIndex > -1 AndAlso e.ColumnIndex + 1 <= DataGridView1.Columns.Count - 1) Then Dim cell As DataGridViewCell = DataGridView1(e.ColumnIndex + 1, e.RowIndex) If (cell.Value IsNot Nothing) Then MessageBox.Show(cell.Value.ToString()) End If End Sub This code works with every column (except, logically, with the last one); you have to adapt it to work just with the column(s) you wish.
CellClick event of the DataGridView (but all the events have the two arguments e and sender). Just write this code and will work (you have to adapt the Handles DataGridView1.CellClick part to the name of your datagridview if it is not DataGridView1).