Filter listbox items using textbox c#

M

marcelo

Could you help me out here. I need to accomplish this:
I need to filter listbox items from by entering some characters to the
textbox. But the problem is that items (files that are read from directory)
in the listbox has the same name in the beginning, for example
'2007_<docNo>_<CustomerName_ItemSold>.doc'. And the information I need to
find is in the middle of a item name. How do I filter from anywhere (not
from the same beginning) in the item's name?
At the moment by entering some characters it selects items that were found
and here's the following code on textbox_textchange event:

listBox2.ClearSelected();
searchString2 = textBox2.Text;
listBox2.SelectionMode = SelectionMode.MultiExtended;
int x = -1;

if (searchString2.Length != 0)
{
do
{
x = listBox2.FindString(searchString2, x);
if (x != -1)
{
if (listBox2.SelectedIndices.Count > 0)
{
if (x == listBox2.SelectedIndices[0])
return;
}
listBox2.SetSelected(x, true);
}
}
while (x != -1);
}


I having trouble finding any example of this.
thanks a lot
P.S. hope I made myself clear
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top