DataGridView에서 행 번호를 얻습니다
-
05-07-2019 - |
문제
행 번호 DatagridView 셀을 어떻게 얻습니까? 구체적으로, 사용자가 단일 셀을 선택한 경우 해당 행 번호를 어떻게 얻을 수 있습니까? 사용자가 선택한 내용에 따라 특정 셀에 액세스해야합니다.
Removeat 방법을 사용하여 Focus에서 제거 할 수 있지만 Focus에서 행 번호를 얻을 수는 없습니까?
도와 주셔서 감사합니다!
다른 팁
이것은 잘 작동합니다.
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
거의 동일하지만이 솔루션을 사용할 수도 있습니다.
var row = dataGridView1.CurrentRow.Index
다른 방법으로 DatagridView와 사용자 상호 작용을 추적 해야하는 경우 : Me.i_selcol 및 Me.i_selrow 열 및 행 좌표를 사용하는 일부 일반적인 기능으로 추가 처리가 있지만 관련이 없기 때문에 표시하지 않았기 때문에 표시되지 않았습니다. OP에.
안부, Rob
Private Sub I_DataGridView_CurrentCellChanged(sender As Object, e As EventArgs) Handles I_DataGridView.CurrentCellChanged
If Me.I_DataGridView.CurrentCellAddress.X < 0 Or Me.I_DataGridView.CurrentCellAddress.Y < 0 Then Exit Sub
' The Windows Me.I_DataGridView object will have already deselected the current cell and selected the
' new cell as per user navigation using mouse or cursor keys. We just need to store the current
' co-ordinates for the currently selected cell.
Me.I_SelCol = Me.I_DataGridView.CurrentCellAddress.X
Me.I_SelRow = Me.I_DataGridView.CurrentCellAddress.Y
Exit Sub
제휴하지 않습니다 StackOverflow