0

現在、私のアプリケーションは式で 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() がワイルドカードをサポートしていれば設定されますが、残念ながらそうではありません。

4

1 に答える 1

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
于 2015-04-13T17:19:37.863 に答える