Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# FlowLayoutPanel中的过滤器控件?_C#_Search_User Controls_Flowlayout - Fatal编程技术网

C# FlowLayoutPanel中的过滤器控件?

C# FlowLayoutPanel中的过滤器控件?,c#,search,user-controls,flowlayout,C#,Search,User Controls,Flowlayout,我有一个FlowLayoutPanel,其中填充了一个自定义的用户控件,在表单顶部有一个文本框,我想用它来过滤结果。每个UserControl都存储其属性,但我不确定如何使用这些属性进行过滤 例如,假设myUserControl包含如下内容: // snip.. public string Text { get; set; } public string Description { get; set; } //snip.. private textBoxTextChanged(obj send

我有一个FlowLayoutPanel,其中填充了一个自定义的
用户控件
,在表单顶部有一个
文本框
,我想用它来过滤结果。每个
UserControl
都存储其属性,但我不确定如何使用这些属性进行过滤

例如,假设my
UserControl
包含如下内容:

// snip..
public string Text { get; set; }
public string Description { get; set; }
//snip..
private textBoxTextChanged(obj sender, EventArgs e)
{
    foreach(UserControl uc in flowLayoutPanel.Children)
    {
        if(!uc.Text.Contains(textBox.Text) && !uc.Description.Contains(textBox.Text))
        {
            uc.Visibility = Visibility.Collapsed;
        }
        else
        {
            //Set Visible if it DOES match
            uc.Visibility = Visibility.Visible;
        }
    }
}
然后如何从
文本框中获取条目,并将其与
[usercontrol].Text
[usercontrol].Description进行比较?它必须在文本内部搜索,而不仅仅是从一开始

一旦我过滤了适当的结果,我希望这些是唯一可见的。我是否必须将它们全部刷新并仅使用适用的进行重建,或者我是否可以删除与过滤器不匹配的那些


我知道这可能是一个很难回答的问题,我只是不知道从哪里开始。有什么想法吗?

您可以循环查看
TextBoxChanged
事件上的所有用户控件,如果它不符合您的条件,请将可见性设置为折叠。它看起来像这样:

// snip..
public string Text { get; set; }
public string Description { get; set; }
//snip..
private textBoxTextChanged(obj sender, EventArgs e)
{
    foreach(UserControl uc in flowLayoutPanel.Children)
    {
        if(!uc.Text.Contains(textBox.Text) && !uc.Description.Contains(textBox.Text))
        {
            uc.Visibility = Visibility.Collapsed;
        }
        else
        {
            //Set Visible if it DOES match
            uc.Visibility = Visibility.Visible;
        }
    }
}

好消息:它起作用了。坏消息:当遍历近500个对象时,它会锁定大约半分钟。有没有更快的方法?或者,可能是在
BackgroundWorker
?编辑中使用了一些混乱的方法-我不认为它迭代了太多的对象而减慢了速度,我认为它实际上改变了影响它的
可见性。有没有办法让这更顺利?对,这是个问题。您实际上是一次显示所有500个对象吗?或者限制显示的数量有意义吗?在单独的线程中使用搜索委托尝试此操作。这将释放GUI并将繁重的工作转移到代理上。