I have a method that I want to use to filter a listview. I am creating the listview dynamically therfore I don’t know the number of colums in advance. lstCurrentDynamicItems is a class with just one property and that property is named c and its type is object[]. I created that class in order to hold objects of the listview. If I always would have the same listview then I would have no problem building the following method. How could I implement the following method?
public void filterListView(string[] columnsContains)
{
// lstCurrentDynamicItems is a list of objects
// columnsContains is what I want to filter.
var qr = from a in lstCurrentDynamicItems
where a.c[0].ToString().Contains(columnsContains[0]) &&
a.c[1].ToString().Contains(columnsContains[1]) &&
a.c[2].ToString().Contains(columnsContains[2]) &&
// ...
// ...
// ...
a.c[columnsContains.Length].ToString().Contains(columnsContains[columnsContains.Length])
select a;
listView.DataContext = qr;
}
Something like this should work: