[英]Need help filtering an AlphaKEyGroup
我一直在搜索站点和互联网,试图找到解决方案,但找不到。
我已使用Microsoft提供的AlphaKeyGroup示例订购了商品。 但是,用户也将在顶部有一个搜索框,以过滤此列表,我不知道如何进行过滤。
女士说
private void getListItems()
{
var alphaKeyGroup = AlphaKeyGroup<Stores>.CreateGroups(
Database_Controller.getStoreValues(), // basic list of items
(Stores s) => { return s.Name; }, // the property to sort
true); // order the items
// returns type List<AlphaKeyGroup<SampleItem>>
ListViewCollectionSource.Source = alphaKeyGroup;
}
所以我尝试了这两种方式
var alphaKeyGroup = AlphaKeyGroup<Stores>.CreateGroups(Database_Controller.getStoreValues(), (Stores s) => s.Name, true).Where(s => Name.Contains(searchKeyword.Text));
var alphaKeyGroup = AlphaKeyGroup<Stores>.CreateGroups(Database_Controller.getStoreValues(), (Stores s) => { return s.Name.Where(s.Name.Contains(searchKeyword.Text)) ; },true);
第一个不带任何内容给ListView,第二个不编译。
我究竟做错了什么?
我已经找到了解决此问题的方法,并且工作正常!!!
(无论如何,你们告诉我这是否是最好的方法)
private void storeTesting(object sender, TextChangedEventArgs e)
{
List<Stores> storeTest = new List<Stores>();
try
{
if (searchKeyword.Text != "")
{
Debug.WriteLine(searchKeyword.Text);
foreach (Stores storeToShow in storesSource)
{
if (storeToShow.Name.Contains(searchKeyword.Text))
{
storeTest.Add(storeToShow);
}
}
}
else
{
Debug.WriteLine(searchKeyword.Text + "the text is null");
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
}
var alphaKeyGroup = AlphaKeyGroup<Stores>.CreateGroups(storeTest, (Stores s) => { return s.Name; }, true);
ListViewCollectionSource.Source = alphaKeyGroup;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.