Tell listBox how to convert the found value in a listBox to a readable form? When the value in texBox same, but different in case, the search for the value does not work.

 if (!listBox1.Items.Contains(textBox1.Text)) 

If the first value is C:\Users\SERVER\AppData , and the second is absolutely the same but contains the uppercase characters C:\Users\SERVER\AppDATA , the list search does not work: enter image description here

After adding, we get two identical values: enter image description here

  • You in the previous question gave an answer about .ToLower() ... - EvgeniyZ
  • I would not write just like that, I tried with .ToLower() comparison does not work at all. - Vitokhv
  • Write a self-sufficient example with .ToLower() , where you can clearly see that this option does not work. If you, of course, did something like this if (foo.ToLower() == bar.ToLower()) - Aqua
  • It seems I understood what the problem is, literally in an hour I will be at home, I will write the answer. - Aqua
  • one
    Items is a collection, and you translate it into a String ... You should have something like ...Items.Any(x=>x.ToLower() == textBox1.Text.ToLower()) . - EvgeniyZ

1 answer 1

Looking at the example, I can assume that this option will suit you:

 if (!listBox1.Items.Contains(textBox1.Text)) 

This code will not work, because you are simply comparing two lines. And their register also.

Based on this line APPdAtA != AppData

I think the view code:

 foreach (string item in listBox1.Items) { if (item.ToLower() == textBox1.Text.ToLower()) break; else DoSome(); } 

It will work great.

Good luck learning C #

Aqua_

  • Unfortunately, this code ( item.ToLower() ) will not compile (. So it’s not going to work, let alone to "great." - Igor
  • @Igor seems to be rules. A serious mistake on my part. Sorry - Aqua