0

I have a list of objects called images which are obtained from parsing through a text file. They contain details such as the catagory and description. I want to be able to search through the list to find the images with a certain catagory and then display them on a form i have setup. I want to filter through them and then also be able to revert back to the unfiltered view aswell.

class Image
{
    public string FileName { set; get; }
    public string Description { set; get; }
    public string Catagory { set; get; }
    public string Date { set; get; }
    public string Comments { set; get; }
}

This is what i want to do in Linq

string chosenCatagory = CatagoryComboBox.Text;

ImageList = ImageList.Where(x => x.Catagory == chosenCatagory).ToList();

What would be the best way to approach this without using Linq?

0

2 Answers 2

4

You can use List's FindAll method:

ImageList = ImageList.FindAll(x => x.Catagory == chosenCatagory);
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot, next thing is how can i revert back to the unfiltered view as well after filtering it?
0

Use two Lists. ImageList which contains all data and DisplayList which is filled only with the stuff you want to display.

DisplayList = ImageList.FindAll(x => x.Catagory == chosenCatagory);

And if you want to revert set DisplayList back to ImageList.

DisplayList = ImageList;

Also have a look at CollectionView when you wanna do more advanced stuff. It supports filtering, grouping and sorting.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.