JD2022-TU1/main/tools/framework/JD.Winforms/CommonDialogs/Tools.cs

51 lines
1.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace JD.Winforms.CommonDialogs
{
public class Tools
{
public static void ApplyFilterOnComponentList(string _text, List<string> _list, ListBox _listBox, List<string> _listNoInsert)
{
bool addAll = _text.Trim().Length == 0;
string[] searchTextList = _text.Trim().ToLower().Split(' ');
_listBox.BeginUpdate();
// fill lists
_listBox.Items.Clear();
if (_list != null)
{
foreach (string elem in _list)
{
if (_listNoInsert != null && _listNoInsert.IndexOf(elem) >= 0)
continue;
bool find = false;
bool findAll = true;
foreach (string searchText in searchTextList)
{
if (elem.ToLower().Contains(searchText))
find = true;
else
{
findAll = false;
break;
}
}
if (addAll || (find && findAll))
{
_listBox.Items.Add(elem);
}
}
}
_listBox.EndUpdate();
}
}
}