Filter search in listbox textbox

0

I need to filter the data that is displayed in a listbox. In a textbox I write the number that I need, the problem is that in the listbox it only shows me the value when I write it the same, I need to do a search that compares the numbers as it is written in the textbox, regardless of whether the numbers have uppercase letters or mini-maps, the search should always be done.

This way I was doing it in the text changed event but it is only fulfilled when it is equal to the textbox number:

lbPartes.Items.Clear();
  foreach (DataRow rw in fw.dtAllTable.Rows)
  {
  if (rw["Circuit"].ToString() == txtBuscar.Text)
  {
  lbPartes.Items.Add(rw["Circuit"].ToString());
  break;
  }
   }
  partRelCode = -1;
    
asked by Ronald López 28.05.2018 в 22:52
source

1 answer

0

If I did not understand your question wrongly, instead of rw["Circuit"].ToString() == txtBuscar.Text you should use

rw["Circuit"].ToString().Contains(txtBuscar.Text)

That way, the condition will be fulfilled if rw["Circuit"] contains the string you type in the TextBox , not only in the case that it is the same

You also have the possibility to use .StartsWith() that works in the same way as a .Contains() but will only be true if the string begins with the typed letters.

Greetings!

    
answered by 28.05.2018 в 23:09