Click here to Skip to main content
16,015,094 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Assuiming this is shown in a ListView
A1 - desc0 - 0
A1 - desc1 - 1
A1 - desc2 - 2
A1 - desc1 - 2
A2 - desc0 - 0
A2 - desc1 - 1
A3 - desc0 - 0
A3 - desc1 - 1



I have a list shown above. I want to filter it or just display a list with the specified value that I want. For example I just want to view all items that has a value of desc0 and desc2 with a marker of A1 and A3 with a page number of 0.

so the listview will only show:

A1 - desc0 - 0
A3 - desc0 - 0



Something like that. how should I do it? (kindly provide some code snippet)

I am having problems doing the filtering when i have a multiple specified items to be filtered.
Posted
Updated 28-Oct-10 20:12pm
v2
Comments
Tarun.K.S 29-Oct-10 3:36am    
are you using some kind of data binding to get these Listview items?

C#
public class SearchList
    {
        public string Name { get; set; }
        public string Desc { get; set; }
        public int Page { get; set; }
    }

static void Main()
{

List<SearchList> searchList = new List<SearchList> {new SearchList{Name="A1",Desc="desc0",Page=0 },
new SearchList{Name="A1",Desc="desc1",Page=1 },
new SearchList{Name="A1",Desc="desc2",Page=2 },
new SearchList{Name="A1",Desc="desc1",Page=2 },
new SearchList{Name="A2",Desc="desc0",Page=0 },
new SearchList{Name="A2",Desc="desc1",Page=1 },
new SearchList{Name="A3",Desc="desc0",Page=0 },
new SearchList{Name="A3",Desc="desc1",Page=1 }

};

var query = searchList.Where(a => a.Name == "A1" && a.Desc == "desc0" && a.Page == 1);
}
 
Share this answer
 
Comments
Radhakrishnan G. 29-Oct-10 7:16am    
Yea this is the right one ;-)
If you can bind a data source to your ListView, then LINQ is the better way to provide the same. For example entires in your ListView may be a collections of string or other objects, you can write query with the required condition.

listView1.DataSource = for str in strings where str.Contains( "desc0" ) or str.Contains( "desc2");

syntax may not be proper because I have tried this with VB

I hav'nt tried this with ListView
 
Share this answer
 
v2

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