如何獲得每個列表條目的內容與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