![](/img/trans.png)
[英]How to get visible row count of DataGridView after BindingSource.Filter?
[英]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.