如何获得每个列表条目的内容与textQuery.Text
进行测试,并且如果它是命中记录,将被写入名为listResx
的ListView中的四列中?在LINQ中查询/搜索列表(在某些情况下)
-1
A
回答
1
var resultList = MasterList.Where(x => x.id == textQuery.Text || x.en == textQuery.Text || x.fr == textQuery.Text || x.es == textQuery.Text).ToList();
这应该给你小,从而匹配列表。你可以从那里拿走吗?
0
string keyword = textQuery.Text;
var hitsQuery = from i in MasterList
where i.en == keyword ||
i.es == keyword ||
i.fr == keyword ||
i.id == keyword
select i;
var hits = hitsQuery.ToList();
hist
将是List<TransResource>
。您可以使用它来填充您的ListView
,例如使用DataSource
属性:
listResx.DataSource = hits;
listResx.DataBind();
+0
不幸的是,WinForms的ListView没有DataSource和DataBind ala WebForms。另外,'MasterList'不是数据源,而是'resources.Values' – 2013-03-15 21:52:08
0
试试这个:
var matches = resources.Values.Where(x=>x.id==txtQuery.Text ||
x.en==txtQuery.Text ||
x.fr==txtQuery.Text ||
x.es==txtQuery.Text);
foreach(var item in matches)
{
string displayItem = item.id + " " + item.en;
listResx.Items.Add(new ListViewItem(displayItem));
}
或用更少的代码去:
foreach(var item in resources.Values.Where(x=>x.id==txtQuery.Text ||
x.en==txtQuery.Text ||
x.fr==txtQuery.Text ||
x.es==txtQuery.Text))
{
string displayItem = item.id + " " + item.en;
listResx.Items.Add(new ListViewItem(displayItem));
}
相关问题
- 1. 在某些情况下修改Solr搜索查询文本
- 2. 在某些情况下
- 3. 在某些情况下
- 4. System.Security.Cryptography.ProtectedData.Unprotect在某些情况下
- 5. 如何在某些情况下序列化某些属性
- 6. Facebook FQL查询在某些情况下不返回结果
- 7. 库查询 - > setLimit(4)返回在某些情况下
- 8. 如何在某些条件下在linq查询中分配两个列表?
- 9. 占位符检查在某些情况下有效,并且在某些情况下不会
- 10. 在不进行sql查询的情况下搜索datagridview
- 11. 在没有第二个查询的情况下搜索关系
- 12. 阵列在LINQ查询搜索参数
- 13. SQL只评估某些情况某些情况下db2和sybase
- 14. Android在某些情况下崩溃
- 15. vb.net FTP - 工作在某些情况下
- 16. 在某些情况下防止null
- 17. PowerBIClient在某些情况下生成System.ArrayTypeMismatchException
- 18. php:在某些情况下避免__get?
- 19. 的UIImageView autoresizingmask在某些情况下
- 20. fn_cdc_map_lsn_to_time在某些情况下返回NULL
- 21. 在某些情况下创建它
- 22. ExtJS的5 rowediting在某些情况下
- 23. 使用@XmlTransient只在某些情况下
- 24. 在某些情况下隐藏CheckBoxPreference
- 25. 在某些情况下只保存NSManagedContext
- 26. RichEditBox在某些情况下崩溃。
- 27. GridView HeaderText在某些情况下为空
- 28. 在某些情况下的IdentifierForVendor值
- 29. Rails - 在某些情况下使用CSS
- 30. 如何让javax.validation在某些情况下
我很困惑,你问什么。 textQuery.Text在哪里?您希望使用哪个查询操作符(例如,我们在寻找什么,什么定义了“命中”)?我们的源数据在哪里? – theMayer 2013-03-15 21:51:51
也许这可以帮助未来:http://code.msdn.microsoft.com/101-LINQ-Samples-3fb9811b :-) – 2013-03-15 22:02:09