469,612 Members | 1,554 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,612 developers. It's quick & easy.

Filter listbox items using textbox (winforms)

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
Mar 28 '07 #1
0 2410

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by L.Peter | last post: by
2 posts views Thread by John R. | last post: by
6 posts views Thread by Janaka | last post: by
3 posts views Thread by Ali Chambers | last post: by
9 posts views Thread by zdrakec | last post: by
reply views Thread by devrayhaan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.