本文介绍了过滤具有指定值的列表视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设这在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



我上面有一个清单.我要过滤它,或者只显示具有我想要的指定值的列表.例如,我只想查看具有desc0和desc2值的所有项目,标记A1和A3的页码为0.

因此listview将仅显示:

A1-desc0-0
A3-desc0-0



这样的事情.我该怎么办? (请提供一些代码段)

当我有多个要过滤的指定项目时,我在进行过滤时遇到问题.

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.

推荐答案

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


静态void Main()
{

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

};

var query = searchList.Where(a => a.Name =="A1"&& a.Desc =="desc0"&& a.Page == 1);
}


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);
}



这篇关于过滤具有指定值的列表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 00:19