如何獲得每個列表條目的內容與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. 如何在某些情況下序列化某些屬性
- 2. 庫查詢 - > setLimit(4)返回在某些情況下
- 3. 在沒有第二個查詢的情況下搜索關係
- 4. 佔位符檢查在某些情況下有效,並且在某些情況下不會
- 5. 陣列在LINQ查詢搜索參數
- 6. Android在某些情況下崩潰
- 7. 在某些情況下防止null
- 8. PowerBIClient在某些情況下生成System.ArrayTypeMismatchException
- 9. AspectJ和Spring IOException在某些情況下
- 10. 的UIImageView autoresizingmask在某些情況下
- 11. 在某些情況下只保存NSManagedContext
- 12. php:在某些情況下避免__get?
- 13. GridView HeaderText在某些情況下爲空
- 14. 使用@XmlTransient只在某些情況下
- 15. 在某些情況下創建它
- 16. 在某些情況下查找矩陣中的相同數字
- 17. 突出顯示搜索結果在某些情況下不起作用
- 18. LINQ搜索查詢
- 19. 在Linq查詢中搜索任何詞
- 20. Linq查詢與空檢查以獲得在不同情況下
- 21. SQL情況下,搜索
- 22. 在某些情況下ORM額外的計算列?
- 23. 刪除的情況下某些其他情況下
- 24. 在不使用exec的情況下運行MySQL查詢列表()
- 25. 正則表達式替換零在某些情況下
- 26. 正則表達式 - 在某些情況下不起作用
- 27. 爲命名的SQL表約定在某些情況下
- 28. 在某些情況下修改表的值
- 29. 防止在某些情況下提交表格
- 30. Reporting Services表達式在某些情況下會出錯
我很困惑,你問什麼。 textQuery.Text在哪裏?您希望使用哪個查詢操作符(例如,我們在尋找什麼,什麼定義了「命中」)?我們的源數據在哪裏? – theMayer 2013-03-15 21:51:51
也許這可以幫助未來:http://code.msdn.microsoft.com/101-LINQ-Samples-3fb9811b :-) – 2013-03-15 22:02:09