【发布时间】:2015-04-01 13:49:51
【问题描述】:
这个问题之前在 StackOverflow 上被问过,所以你可能认为它是重复的,但我已经尝试了许多解决方案,但我仍然卡住了。
我有一个绑定到 LINQ 查询的 WinForms CheckedListBoxControl,但我无法获取 Value 和 DisplayMembers。
以下是获取 Value 和 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
}
【问题讨论】:
-
什么
item.GetType()?您使用标准的CheckedListBox 或一些带有控件的第三方库? -
我试过标准的和 DevExpress 的。我不介意哪一个有效。出于本文的目的,我将不得不查看标准控件,因为这不是 devExpress 论坛。
-
item.GetType() = Name = "f__AnonymousTypeb6`2"
标签: c# linq checkedlistbox