[英]Can someone tell me what's wrong with this code?
I'm trying to implement a search as you type (like in iTunes). 我正在尝试在您键入时实现搜索(如在iTunes中)。 I am using an ObjectListView .
我正在使用ObjectListView 。 Further, I have a textbox that is used to do the search as shown below:
此外,我有一个用于搜索的文本框,如下所示:
private void textBoxSearch_TextChanged(object sender, EventArgs e)
{
string txt = textBoxSearch.Text;
TextMatchFilter filter = null;
if (!String.IsNullOrEmpty(txt))
{
filter = TextMatchFilter.Contains(myObjectListView, txt);
}
// Setup a default renderer to draw the filter matches
if (filter == null)
myObjectListView.DefaultRenderer = null;
else
{
myObjectListView.DefaultRenderer = new HighlightTextRenderer(filter);
// Uncomment this line to see how the GDI+ rendering looks
myObjectListView.DefaultRenderer = new HighlightTextRenderer { Filter = filter, UseGdiTextRendering = false };
}
// Some lists have renderers already installed
HighlightTextRenderer highlightingRenderer = myObjectListView.GetColumn(0).Renderer as HighlightTextRenderer;
if (highlightingRenderer != null)
highlightingRenderer.Filter = filter;
myObjectListView.ModelFilter = filter;
}
Can someone figure out why this doesn't work? 有人能弄清楚为什么这不起作用? The above code is meant to filter search results as the user types in the textbox (Like iTunes does, if you have ever used itunes).
上面的代码用于在用户在文本框中键入时过滤搜索结果(如果你曾经使用iTunes,就像iTunes一样)。 Apparently, up to this point, nothing happens.
显然,到目前为止,没有任何反应。 It seems like this code does not even execute.
看起来这个代码甚至都没有执行。
对此 , ObjectListView
有一个名为UseFiltering
的属性,默认情况下为false
,必须设置为true
才能启用过滤。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.