我希望能够过滤包含1000个字符串的列表框,每个字符串长度为50-4000个字符,因为用户在文本框中输入没有延迟.
我目前正在使用一个计时器,TextChanged在300毫秒内没有触发文本框事件后更新列表框.然而,这是非常生涩,ui有时会暂时冻结.
实现与此类似的功能的常规方法是什么?
编辑:我正在使用winforms和.net2.
谢谢
这是我目前使用的代码的精简版本:
string separatedSearchString = this.filterTextBox.Text;
List<string> searchStrings = new List<string>(separatedSearchString.Split(new char[] { ';' },
StringSplitOptions.RemoveEmptyEntries));
//this is a member variable which is cleared when new data is loaded into the listbox
if (this.unfilteredItems.Count == 0)
{
foreach (IMessage line in this.logMessagesListBox.Items)
{
this.unfilteredItems.Add(line);
}
}
StringComparison comp = this.IsCaseInsensitive
? StringComparison.OrdinalIgnoreCase
: StringComparison.Ordinal;
List<IMessage> resultingFilteredItems = new List<IMessage>();
foreach (IMessage line in this.unfilteredItems)
{
string message = line.ToString();
if(searchStrings.TrueForAll(delegate(string item) { return message.IndexOf(item, …Run Code Online (Sandbox Code Playgroud)