如果具有多个Gridview的表单,如何选中哪个Gridview?

时间:2013-06-17 18:42:33

标签: winforms c#-3.0

在表单中我创建了三个动态Gridview ,我想对特定Gridview的选择执行一些特定的操作,任何人都可以帮我知道哪个gridview得到了seletec?

1 个答案:

答案 0 :(得分:0)

DataGridView上有一个.GotFocus()事件,可用于在表单范围(或全局)变量中存储某些内容。 (对不起VB ...)

Dim LastGirdWithFocus As String = ""

Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
    MsgBox(LastGirdWithFocus)
End Sub

Private Sub dgv1_GotFocus(sender As Object, e As System.EventArgs) _
    Handles dgv1.GotFocus, dgv2.GotFocus
    LastGirdWithFocus = sender.name
End Sub