Mohamed Moumni

Mohamed Moumni

  • NA
  • 48
  • 7.8k

Why do I find the result repeats after the search?

Jun 28 2017 3:28 PM
i use this methode to search for every keyword in textbox1 ind have the result in the listbox2 . But the problem that the results are repeated .
 


this code used in search button
  1. private void button1_Click(object sender, EventArgs e)  
  2. {  
  3. // the keyword in text box  
  4. string[] pattern = textBox1.Text.Split(new[] { ' ' },StringSplitOptions.RemoveEmptyEntries);  
  5. // list_temporare for items in listbox 1  
  6. List<DirectoryInfo> list_temporare = new List<DirectoryInfo>();  
  7. // listbox2 for show result  
  8. listBox2.Items.Clear();  
  9. // 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)  
  10. foreach (DirectoryInfo dr in listBox1.Items)  
  11. {  
  12. list_temporare.Add(dr);  
  13. }  
  14. // search for every key word in pattern  
  15. var liste_resultat = (from drc in list_temporare  
  16. where pattern.All(s => drc.ToString().ToLower().Contains(s.ToLower()))  
  17. select drc);  
  18. // show result in listbox2  
  19. foreach (DirectoryInfo dr in liste_resultat)  
  20. {  
  21. listBox2.Items.Add(dr);  
  22. }  


Answers (1)