【问题标题】:Datagrid text search数据网格文本搜索
【发布时间】:2013-05-10 05:35:05
【问题描述】:

我想在数据网格中搜索一个文本,像下面这样写的代码给出了错误

For i As Integer = 0 To _dt.Items.Count - 1
            Dim row As DataGridRow = DirectCast(_dt.ItemContainerGenerator.ContainerFromIndex(i), DataGridRow)
            For j As Integer = 0 To _dt.Columns.Count - 1
                If row IsNot Nothing Then
                    Dim cellContent As TextBlock = TryCast(_dt.Columns(j).GetCellContent(row), TextBlock)
                    If cellContent IsNot Nothing AndAlso cellContent.Text.Equals(txtfind.Text) Then
                        _dt.ScrollIntoView(row, _dt.Columns(j))
                        Dim presenter As DataGridCellsPresenter = GetVisualChild(Of DataGridCellsPresenter(row))
                        Dim cell As DataGridCell = DirectCast(presenter.ItemContainerGenerator.ContainerFromIndex(j), DataGridCell)
                        _dt.SelectedItem = cell
                        cell.IsSelected = True
                        row.MoveFocus(New TraversalRequest(FocusNavigationDirection.[Next]))
                        Exit For
                    End If
                End If
            Next
        Next

行错误:数组边界不能出现在类型说明符中。 声明:Dim presenter As DataGridCellsPresenter = GetVisualChild(Of DataGridCellsPresenter(row))

帮助表示赞赏 abhimoh

【问题讨论】:

标签: wpf wpfdatagrid


【解决方案1】:

变化:

   Dim presenter As DataGridCellsPresenter = GetVisualChild(Of DataGridCellsPresenter(row))

'you have created an array with row number of values.

到:

   Dim presenter As DataGridCellsPresenter = GetVisualChild(Of DataGridCellsPresenter)(row)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-22
    • 2013-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-27
    • 2015-04-24
    • 1970-01-01
    相关资源
    最近更新 更多