Click here to Skip to main content
15,884,933 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
The following code working well with basics but I would like to update with speacial request.

C#
My_listBox.SelectedItems.Clear();

for (int i = My_listBox.Items.Count - 1; i >= 0; i--)
{
    if (My_listBox.Items[i].ToString().ToLower().Contains(My_textBox_Search.Text.ToLower()))
    {
        if (My_listBox.Items.Count == null)
        {
            MessageBox.Show("No matches found.");
        }
        else
        {
            My_listBox.SetSelected(i, true);
        }
    }
    else
    {
        My_textBox_ResultOfSearchListedData.Text = My_listBox.SelectedItems.Count.ToString();
    }


I try to add notification message when nothing found after search?

Found the right text what is selected on ListBox but how to remove anything elese from the list?

I also want keep the counter how much selected (found items) in the list?

What I have tried:

My_listBox.Items.Remove(i);
My_listBox.Items.RemoveAt(i);
My_listBox.Items.ToString().Remove(i);
Posted
Updated 22-Oct-22 4:01am
v3
Comments
[no name] 22-Oct-22 19:11pm    
How long is your list? Seems it would be simpler to let the user search / scroll and click, then delete the selected item. The list should be sorted.
ernteSKY 23-Oct-22 19:13pm    
I trying to creat a search filter. I want keep all items and shown (right now all selected) what is fit for a search term (only text like: ABC) then the rest items (not selected) have to remove from the list.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900