簡體   English   中英

DataGridView行過濾器不適用

[英]DataGridView Row Filter not applying

我有一個DataGridView1,我正在嘗試使用行過濾器對其進行過濾。 我也有一個字符串:SomethingHere

我有一個FilterString,它以以下格式用作字符串:

 Dim DGVDV As New DataView
 Using iConn As New OleDbConnection(ConnString)
      Using iDA As New OleDbDataAdapter(iSelectString, Conn)
           iDA.MissingSchemaAction = MissingSchemaAction.AddWithKey
           iDA.FillSchema(DS.Tables("Table"), SchemaType.Source)
           iDA.Fill(DS.Tables("Table"))
           iBS.DataSource = DS.Tables("Table")
           DGVDV = DS.Tables("Table").DefaultView

           With DataGridView1
                .DataSource = iBS
           End With
      End Using
 End Using





 DGVDV = DS.Tables("Table").DefaultView
 DGVDV.RowFilter = FilterString

為了證明它能正常工作,我在下面進行了說明:

 Msgbox("Filter: " & DGVDV.RowFilter.ToString)

僅當FilterString為以下格式時,才會觸發此消息框:

 FilterString = "[Status] = '" & SomethingHere & "'"

但是,行過濾器似乎忽略了以下兩個字符串:

 FilterString = "([Status] = '" & CMBFilter & "')" & " AND ([ID] LIKE '%" & SomethingHere & "%' OR [Name] LIKE '%" & SomethingHere & "%')"

 FilterString = "([ID] LIKE '%" & TextFilter & "%' OR [Name] LIKE '%" & TextFilter & "%')"

我嘗試了谷歌搜索,但我只是想不出問題所在。

    If CMBBool = True And TextBool = False Then
        FilterString = "[Status] = '" & CMBFilter & "'"
    ElseIf CMBBool = False And TextBool = True Then 
        FilterString = "([ID] LIKE '%" & TextFilter & "%' OR [Name] LIKE '%" & TextFilter & "%')"
        MsgBox(FilterString)
    ElseIf CMBBool = True And TextBool = True Then
        FilterString = "([Status] = '" & CMBFilter & "')" & " AND ([ID] LIKE '%" & TextFilter & "%' OR [Name] LIKE '%" & TextFilter & "%')"
        MsgBox(FilterString)
    ElseIf CMBBool = False And TextBool = False Then
        FilterString = String.Empty
    End If
    DGVDV.RowFilter = FilterString
    MsgBox("Filter: " & DGVDV.RowFilter.ToString)

當FilterString如下

 FilterString = "[Status] = '" & CMBFilter & "'"

Msgbox彈出。 對於其他FilterString,沒有Msgbox彈出,使我懷疑FilterString從未應用於行過濾器。

有人可以幫忙嗎?

使用這種格式可以:

DataView.RowFilter = string.Concat("CONVERT(", COLUMNNAME,",System.String) LIKE '%", TEXTBOXorSTRING, "%'")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM