我已阅读有关此主题的大量帖子,但似乎没有解决我的具体问题。我正在使用带有vb的wpf网格。这是我的事件处理程序:
Private Sub dgrdMain_SelectedCellsChanged(sender As Object, e As SelectedCellsChangedEventArgs) Handles dgrMain.SelectedCellsChanged
If e.RemovedCells.Count > 0 Then
Dim ilRemovedCells As IList(Of DataGridCellInfo) = e.RemovedCells
For Each rc As DataGridCellInfo In ilRemovedCells
rc.Column.DisplayIndex 'This gives the column index
'How do I get the row index?
Next
End If
这里rc =删除了细胞。我的问题是上面的评论专栏。
答案 0 :(得分:2)
这是一个返回索引的快速功能...让我知道这是否是你需要的......
Public Shared Function GetRowIndex(dataGrid As DataGrid, dataGridCellInfo As DataGridCellInfo) As Integer
Dim dgrow As DataGridRow = DirectCast(dataGrid.ItemContainerGenerator.ContainerFromItem(dataGridCellInfo.Item), DataGridRow)
If dgrow IsNot Nothing Then
Return dgrow.GetIndex()
Else
Return -1
End If
End Function