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 _list, ListBox _listBox, List _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(); } } }