在VB.NET中,为特定单元格添加点击事件

3

我有一个单元格在datagridview中,它位于第8行第2列。只有当点击该单元格时,我希望显示“另存为”对话框,但实际上我无法为特定单元格获取单击事件。在vb.net中如何实现这一点?

3个回答

6
在你的dataGridView事件 "DataGridView1_CellClick" 中添加这段代码:
  Private Sub DataGridView1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick

    If e.ColumnIndex = 2 And e.RowIndex = 8 Then
        'Do any thing

        MsgBox("yes" + DataGridView1.Item(e.ColumnIndex, e.RowIndex).Value.ToString())

    End If
End Sub

有点晚了,但是假设我想从另一个事件(比如DataBindingComplete事件)中调用此事件,以便我可以自动单击刚加载的DGV的第一个元素,我该如何调用单元格单击事件? - AMDarwech

0
 Private Sub DataGridView1_CellClick(sender As Object, e As `DataGridViewCellEventArgs`) Handles DataGridView1.CellClick

''Code HERE............

End Sub

0
Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView_pos.CellContentClick
      Dim i As Integer

      With DataGridView_pos
          If e.RowIndex >= 0 Then
              i = .CurrentRow.Index

              txt_update_detail_id.Text = .Rows(i).Cells("id").Value.ToString

          End If
      End With

  End Sub
'txt_update_detail_id.Text Output value by id (Mysql database)
'Is work

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接