I have a DataGridView1 and I'm trying to filter it using a Row Filter. I also have a string: SomethingHere
I have a FilterString that I'm using as a string in the following format:
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 = "[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 = "[Status] = '" & CMBFilter & "'"
The Msgbox pops up. For the other FilterStrings, no Msgbox pops up, making me suspect that the FilterString is never being applied to the row filter.
Can anyone help?
使用这种格式可以:
DataView.RowFilter = string.Concat("CONVERT(", COLUMNNAME,",System.String) LIKE '%", TEXTBOXorSTRING, "%'")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.