【问题标题】:How to jump to a row of a DataView based on partial match search criteria?如何根据部分匹配搜索条件跳转到 DataView 的一行?
【发布时间】:2015-04-09 14:40:55
【问题描述】:

目前,我的应用程序使用表达式上的 RowFilter 属性在 DataView 中搜索用户定义的字符串。目前我的代码看起来像这样:

Public Class MyClass
   Private custView As DataView
Private Sub form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
   dsDataSet = <"DataAccessLayer call to SQL Stored Procedure">
   custView = New DataView(dsDataSet.Tables(0))
   custView.Sort = "Column Name"
   Me.C1FlexGrid1.DataSource = custView
End Sub
Private Sub txtSearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearch.TextChanged
    Dim searchText As String = txtSearch.Text
    Dim expression As String = "Column Name LIKE '" + searchText + "%'"

    custView.RowFilter = expression
    Me.C1FlexGrid1.DataSource = custView
End Sub
End Class

我的目标是修改它的行为,而不是过滤掉不符合搜索结果的行,而是保留所有行,但在用户输入搜索时跳转到部分匹配的第一个实例盒子。如果 DataView.Find() 支持通配符我会设置,但不幸的是它没有。

【问题讨论】:

    标签: vb.net dataset dataview c1flexgrid


    【解决方案1】:

    我想出的解决方案是使用一些迭代逻辑。然而,这是在 DataView 绑定到的对象上完成的,而不是在 DataView 本身上完成的。尽管可以修改此代码以完全做到这一点。

    Private Sub txtSearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearch.TextChanged
            'Unselect all
            Me.C1FlexGrid1.Select(-1, -1, True)
    
            If txtSearch.Text <> "" And [column index] <> -1 Then
                'Typed text
                Dim s As String = txtSearch.Text.Trim.ToLower
                Dim column As Int32 = [column index] + 1
    
                'Recurse until match in first column is found
                For i As Integer = 0 To Me.C1FlexGrid1.Rows.Count - 1
                    If C1FlexGrid1.GetData(i, column) <> Nothing Then
                        If C1FlexGrid1.GetData(i, column).ToString.ToLower.StartsWith(s) Then
                            Me.C1FlexGrid1.Select(i, column, True)
                            Exit Sub
                        End If
                    Else
    
                        MsgBox("Error message", vbOKOnly, "NO MATCHES")
    
                        'Reset search criteria
                        Call ResetSearch()
    
                    End If
                Next
                MsgBox("Error message", vbOKOnly, "NO MATCHES")
            End If
        End Sub
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-13
      • 2017-08-30
      • 1970-01-01
      • 2011-10-19
      • 2013-09-11
      • 1970-01-01
      • 2022-11-01
      • 2012-10-05
      相关资源
      最近更新 更多