Wpf 数据网格文本搜索
我想在datagrid中搜索一个文本,下面编写的代码给出了一个错误Wpf 数据网格文本搜索,wpf,wpfdatagrid,Wpf,Wpfdatagrid,我想在datagrid中搜索一个文本,下面编写的代码给出了一个错误 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
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演示者作为DataGridCellsPresenter=GetVisualChild(DataGridCellsPresenter(行))显示
感谢您的帮助
阿布希摩变化:
Dim presenter As DataGridCellsPresenter = GetVisualChild(Of DataGridCellsPresenter(row))
'you have created an array with row number of values.
致:
这里有一个C#示例,应该很容易转换为VB是的,我想关闭这个线程
Dim presenter As DataGridCellsPresenter = GetVisualChild(Of DataGridCellsPresenter)(row)