简体   繁体   English

DataGridView行过滤器不适用

[英]DataGridView Row Filter not applying

I have a DataGridView1 and I'm trying to filter it using a Row Filter. 我有一个DataGridView1,我正在尝试使用行过滤器对其进行过滤。 I also have a string: SomethingHere 我也有一个字符串:SomethingHere

I have a FilterString that I'm using as a string in the following format: 我有一个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

To prove that it's working, I have right below it: 为了证明它能正常工作,我在下面进行了说明:

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

This messagebox only fires when the FilterString is in this format: 仅当FilterString为以下格式时,才会触发此消息框:

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

However, the Row Filter seems to be ignoring a string like the two below: 但是,行过滤器似乎忽略了以下两个字符串:

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

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

I've tried Googling, and I just can't figure out what the issue is. 我尝试了谷歌搜索,但我只是想不出问题所在。

    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)

When the FilterString is as below 当FilterString如下

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

The Msgbox pops up. Msgbox弹出。 For the other FilterStrings, no Msgbox pops up, making me suspect that the FilterString is never being applied to the row filter. 对于其他FilterString,没有Msgbox弹出,使我怀疑FilterString从未应用于行过滤器。

Can anyone help? 有人可以帮忙吗?

使用这种格式可以:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM