[英]How to show next cell value when one cell is clicked in Datagridview in Messagebox
當在vb.net中單擊一個單元格時,我需要獲取下一個單元格的值。
ID | NAME | 年齡
1 | Azleef | 20
2 | 賽義德 | 22
3 | 吉米 | 23
例如,如果我按Azleef ,則需要下一個單元格。 對應的年齡是20
您可以依靠CellClick
事件獲得所需的功能。 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
這段代碼適用於每一列(邏輯上除外,最后一行除外); 您必須對其進行調整以使其僅與所需的列一起使用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.