【发布时间】:2010-10-08 15:44:30
【问题描述】:
我已经用哈希表绑定了一个列表视图(网格),那么如何从那里获取项目?在使用哈希表之前,我刚刚做了ListViewA.SelectedItems;,我正在获取源代码。
当我使用两个 foreach 循环时,Ir 失败:
dlstTemplates 是我在 WPF 中的 ListView
foreach (var group in dlstTemplates.SelectedItems)
{
foreach (var Template in group)
{
}
}
错误 2 foreach 语句不能 对“对象”类型的变量进行操作 因为“对象”不包含 公共定义 'GetEnumerator' D:\cs_InformeMedico\app\Template.xaml.cs 85 21 Demo.View
我在调试器上发现了这个:
- dlstPlantillas.SelectedItems Count = 1 System.Collections.IList {System.Windows.Controls.SelectedItemCollection}
- [0] {System.Data.Linq.SqlClient.ObjectReaderCompiler.Group<string,Demo.View.Plantilla>} object {System.Data.Linq.SqlClient.ObjectReaderCompiler.Group<string,Demo.View.Plantilla>}
- Non-Public members
+ items Count = 97 System.Collections.Generic.IEnumerable<Demo.View.Plantilla> {System.Collections.Generic.List<Demo.View.Plantilla>}
key "101010112000" string
System.Linq.IGrouping<K,T>.Key "101010112000" string
- Results View Expanding the Results View will enumerate the IEnumerable
+ [0] {Demo.View.Plantilla} Demo.View.Plantilla
+ [1] {Demo.View.Plantilla} Demo.View.Plantilla
+ [2] {Demo.View.Plantilla} Demo.View.Plantilla
+ [3] {Demo.View.Plantilla} Demo.View.Plantilla
+ [4] {Demo.View.Plantilla} Demo.View.Plantilla
+ [5] {Demo.View.Plantilla} Demo.View.Plantilla
+ [6] {Demo.View.Plantilla} Demo.View.Plantilla
+ [7] {Demo.View.Plantilla} Demo.View.Plantilla
+ [8] {Demo.View.Plantilla} Demo.View.Plantilla
+ [9] {Demo.View.Plantilla} Demo.View.Plantilla
+ [10] {Demo.View.Plantilla} Demo.View.Plantilla
- Raw View
- [System.Windows.Controls.SelectedItemCollection] Count = 1 System.Windows.Controls.SelectedItemCollection
+ [0] {System.Data.Linq.SqlClient.ObjectReaderCompiler.Group<string,Demo.View.Plantilla>} object {System.Data.Linq.SqlClient.ObjectReaderCompiler.Group<string,Demo.View.Plantilla>}
+ Raw View
IsFixedSize false bool
IsReadOnly false bool
所以当组是一个
{System.Data.Linq.SqlClient.ObjectReaderCompiler.Group<string,Demo.View.Plantilla>} object type
抱歉,Plantilla = 模板,我将其引述为更容易理解
【问题讨论】: