this code used in search button
- private void button1_Click(object sender, EventArgs e)
- {
- // the keyword in text box
- string[] pattern = textBox1.Text.Split(new[] { ' ' },StringSplitOptions.RemoveEmptyEntries);
- // list_temporare for items in listbox 1
- List
list_temporare = new List (); - // listbox2 for show result
- listBox2.Items.Clear();
- // add all items in listbox1 in list_temporare (Because linq and lambda does not support the items in the box list or that what I believe)
- foreach (DirectoryInfo dr in listBox1.Items)
- {
- list_temporare.Add(dr);
- }
- // search for every key word in pattern
- var liste_resultat = (from drc in list_temporare
- where pattern.All(s => drc.ToString().ToLower().Contains(s.ToLower()))
- select drc);
- // show result in listbox2
- foreach (DirectoryInfo dr in liste_resultat)
- {
- listBox2.Items.Add(dr);
- }
- }
Nilesh ShahPosted Jun 28, 2017, 4:35 PM