使用 "like" searchkey VB.NET 在 flowlayoutpanel 中搜索控件
search controls in flowlayoutpanel with "like" searchkey VB.NET
我有一个列出专辑标题的流程布局面板。假设 flowlayoutpanel 有很多歌曲,我想找到一首特定的歌曲。比方说,我想要 Ed Sheeran "Thinking Out loud." 的歌曲所以我会在搜索框中输入 "Thinking" 这个词,甚至没有完成 "Out Loud" 个词,我想过滤flowlayoutpanel 向我显示标题为 "Thinking Out Loud" 的控件并隐藏所有没有单词 "Thinking." 的控件这就像一个 SQL 搜索 LIKE 查询。但是我不想做SQL。 FLOWLAYOUTPANEL 和 SEARCH TEXTBOX 是否可行?
您可以使用搜索文本框的 TextChanged 事件触发 FlowLayoutPanel
控件集合的处理,根据 [=16] 的结果设置每个控件的 Visible
属性 =] Like Operator比较。
Private Sub tbSearch_TextChanged(sender As Object, e As EventArgs) Handles tbSearch.TextChanged
If tbSearch.Text.Length > 0 Then
Dim compareTo As String = String.Concat("*", tbSearch.Text.ToLowerInvariant, "*")
For Each c As Control In FlowLayoutPanel1.Controls
c.Visible = (c.Text.ToLowerInvariant Like compareTo)
Next
Else
For Each c As Control In FlowLayoutPanel1.Controls
c.Visible = True
Next
End If
End Sub
我有一个列出专辑标题的流程布局面板。假设 flowlayoutpanel 有很多歌曲,我想找到一首特定的歌曲。比方说,我想要 Ed Sheeran "Thinking Out loud." 的歌曲所以我会在搜索框中输入 "Thinking" 这个词,甚至没有完成 "Out Loud" 个词,我想过滤flowlayoutpanel 向我显示标题为 "Thinking Out Loud" 的控件并隐藏所有没有单词 "Thinking." 的控件这就像一个 SQL 搜索 LIKE 查询。但是我不想做SQL。 FLOWLAYOUTPANEL 和 SEARCH TEXTBOX 是否可行?
您可以使用搜索文本框的 TextChanged 事件触发 FlowLayoutPanel
控件集合的处理,根据 [=16] 的结果设置每个控件的 Visible
属性 =] Like Operator比较。
Private Sub tbSearch_TextChanged(sender As Object, e As EventArgs) Handles tbSearch.TextChanged
If tbSearch.Text.Length > 0 Then
Dim compareTo As String = String.Concat("*", tbSearch.Text.ToLowerInvariant, "*")
For Each c As Control In FlowLayoutPanel1.Controls
c.Visible = (c.Text.ToLowerInvariant Like compareTo)
Next
Else
For Each c As Control In FlowLayoutPanel1.Controls
c.Visible = True
Next
End If
End Sub