如何获得行号DataGridView单元格?具体地说,如果用户选择了单个单元格,如何获取行号?它需要根据用户选择的内容访问特定的单元格。
我知道RemoveAt方法可以用来移除焦点,但是你显然不能得到焦点的行号?
谢谢你的帮助!
发布于 2009-09-10 01:30:28
您可以简单地在current cell上使用RowIndex
var row = dataGridView1.CurrentCell.RowIndex;
发布于 2013-10-09 13:22:32
这个运行得很好。
Private Sub DataGridView1_RowPrePaint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewRowPrePaintEventArgs) Handles DataGridView1.RowPrePaint
If e.RowIndex >= 0 Then
Me.DataGridView1.Rows(e.RowIndex).Cells(0).Value = e.RowIndex + 1
End If
End Sub
发布于 2010-06-17 16:33:44
它几乎是相同的,但您也可以使用以下解决方案:
var row = dataGridView1.CurrentRow.Index
https://stackoverflow.com/questions/1402944
复制相似问题