简体   繁体   English

如何从我的DataGridView中的单元格获得控制权?

[英]How get control from cell in my DataGridView?

I would like to know if it's possible to directly get control of a specific cell by using its references / column and row indexes. 我想知道是否可以通过使用其引用/列和行索引直接控制特定单元格。

I noticed that it was possible to get control of a cell from an event. 我注意到有可能从一个事件中控制一个单元格。 For example: 例如:

From the event " myDataGridView.CellValidating " you can obtain the control of the cell being edited as follows 从事件“ myDataGridView.CellValidating ”,您可以获得对正在编辑的单元格的控制,如下所示

Dim cellControl As Control = Me.myDataGridView.EditingControl

Do you think it's possible to get the same thing without using an event? 你认为在不使用活动的情况下可以获得同样的东西吗?

Just pass the column and row you wish to access. 只需传递您想要访问的列和行。

Private Sub GetCellValue(column As Integer, row As Integer)
    Dim x = DataGridView1(column, row).Value.ToString()
    Debug.Print(x)
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    GetCellValue(1, 3)
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM