Newbie
Newbie

Reputation: 1180

How to filter ListBox

the situation is that I have a list with some HubTile(s) in it, is there any way I can filter the ListBox depending on what is written in a TextBox?

For the text box I have the code...

private void textBoxSearch_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.Key == Key.Enter)
        {

        }
    }

Thanks, all help appreciated!

Upvotes: 1

Views: 2442

Answers (1)

Deeko
Deeko

Reputation: 1539

Sure, just store the list of HubTiles in a data structure, and when the user enters a search query, do a LINQ query on that list, and reset the list.

private List<HubTiles> myTiles;    
private void textBoxSearch_KeyDown(object sender, KeyEventArgs e)
{
    if (e.Key == Key.Enter)
    {
       myList.ItemsSource = myTiles.Where(t => t.Title.Contains(textBoxSearch.Text));
    }
}

Upvotes: 1

Related Questions