views:

95

answers:

2

In some cases I've been using a DataTable, filtering it witha DataView and displaying the DataView in a DataGrid. I've recently started switching to using my own classes. For example:

[Serializable]
[System.Xml.Serialization.XmlRoot("Items", Namespace = "http://mycomp.com/test")]
public class Items: List<Item>
{

}

[Serializable]
[System.Xml.Serialization.XmlRoot("Item", Namespace = "http://mycomp.com/test")]
public class Item
{
  //public properties here
}

I then take my Items class and display it in a DataGrid which has worked really well. Is there some way I can apply a filter to my list though? DataView only works on datatables.

+1  A: 

If I understand your question correctly, you could use LINQ to Objects and bind the resulting list to the grid view...

Alejandro Mezcua
+1  A: 

You can use FindAll() method:

List<Items> allItems = /* initialize list */;

List<Items> filteredList =
    allItems.FindAll(item => item.Name.StartsWith("A"));
DK