【问题标题】:How to retrieve the row index from DataGridCellInfo如何从 DataGridCellInfo 中检索行索引
【发布时间】:2016-03-28 03:05:55
【问题描述】:

我已经阅读了很多关于这个主题的帖子,但似乎没有一篇能解决我的具体问题。我正在使用带有 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=删除的单元格。我的问题是上面的评论行。

【问题讨论】:

    标签: wpf vb.net datagrid


    【解决方案1】:

    这是一个返回索引的快速函数...如果您需要,请告诉我...

    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
    

    【讨论】:

      猜你喜欢
      • 2017-05-30
      • 2022-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-27
      相关资源
      最近更新 更多