0
StackOverflow之前已經問過這個問題,所以您可能認爲它是重複的,但我嘗試了很多解決方案,但仍然陷入困境。無法從CheckedListBoxControl綁定到LINQ獲取值和DisplayMember
我有一個綁定到LINQ查詢的WinForms CheckedListBoxControl,我無法獲得Value和DisplayMembers。
下面是一些嘗試獲取價值和DisplayMember值:
var avail = from c in dc.CostCenters
select new { Item = c.CostCenterID,
Description = c.CostCenterID + ": " + c.Description };
myList.DataSource = avail;
myList.DisplayMember = "Description";
//Retrieval:
foreach (var item in myList.CheckedItems)
{
DataRowView row = item as DataRowView; //Try 1: row is empty
string displayMember = item["Description"]; //Try 2: Cannot apply indexing with [] to an expression of type 'object'
var x = item[0]; //Try 3: Cannot apply indexing with [] to an expression of type 'object'
row3 = ((DataRowView)myList.CheckedItems[item]).Row; //Try 5 million: Compile error - invalid arguments
}
what' item.GetType()'?你可以使用標準的[CheckedListBox](https://msdn.microsoft.com/ru-ru/library/system.windows.forms.checkedlistbox(v = vs.110).aspx)或者一些帶有控件的第三方庫? – Grundy 2015-04-01 14:07:24
我試過了標準版和DevExpress版。我不介意哪一個可以工作。爲了這篇文章的目的,我不得不看看標準控件,因爲這不是devExpress論壇。 – 2015-04-02 06:01:51
item.GetType()= Name =「<> f__AnonymousTypeb6'2」 – 2015-04-02 06:27:22