无法将类型为“System.Windows.Controls.SelectedItemCollection”的对象强制转换为类型“System.Collections.Generic.IList`1
在WPF中DataGrid 选择事件中获取SelectedItems
报错如下
无法将类型为“System.Windows.Controls.SelectedItemCollection”的对象强制转换为类型“System.Collections.Generic.IList`1[SomeModel]”。
应该如此使用
System.Collections.IList items = (System.Collections.IList)this.dataGrid.SelectedItems;
//
// 摘要:
// 将 System.Collections.IEnumerable 的元素转换为指定的类型。
//
// 参数:
// source:
// 包含要转换的元素的 System.Collections.IEnumerable。
//
// 类型参数:
// TResult:
// source 中的元素要转换成的类型。
//
// 返回结果:
// 一个 System.Collections.Generic.IEnumerable<T>,包含已转换为指定类型的源序列的每个元素。
//
// 异常:
// System.ArgumentNullException:
// source 为 null。
//
// System.InvalidCastException:
// 序列中的元素不能强制转换为 TResult 类型。
public static IEnumerable<TResult> Cast<TResult>(this IEnumerable source);
无法将类型为“System.Windows.Controls.SelectedItemCollection”的对象强制转换为类型“System.Collections.Generic.IList`1的更多相关文章
- 【Winform】 无法将类型为“System.Windows.Forms.SplitContainer”的对象强制转换为类型“System.ComponentModel.ISupportInitialize”。
问题:将dotnet framework 4.0 切换到2.0时,编译没有问题,在运行时出现如下错误:System.InvalidCastException: 无法将类型为“System.Window ...
- WPF System.InvalidCastException: 无法将类型为“System.Windows.Media.Color”的对象强制转换为类型“System.Windows.Media.Brush”。
场景:添加ComboBox样式,界面卡死,日志异常文件如下: -- ::, | ERROR | System.InvalidCastException: 无法将类型为“System.Windows.M ...
- .net4.0切换2.0时,SplitContainer”的对象强制转换为类型
问 题:将dotnet framework 4.0 切换到2.0时,编译没有问题,在运行时出现如下错误:System.InvalidCastException: 无法将类型为“System.Windo ...
- 保存图片控件上的图片到本地 出现错误:无法将类型为“System.Windows.Media.Imaging.BitmapFrameDecode”的对象强制转换为类型“System.Windows.Media.Imaging.BitmapImage”。
保存图片控件上的图片到本地 出现错误:无法将类型为“System.Windows.Media.Imaging.BitmapFrameDecode”的对象强制转换为类型“System.Windows.M ...
- 无法将类型为“System.Decimal”的对象强制转换为类型“System.Char[]”。
在用微软的SSIS操作ORACLE 数据源的时候碰到以下报错信息: [ADO NET Destination [13455]] 错误: 数据插入期间出现异常,从提供程序返回的消息为:无法将类型为&qu ...
- Web Service接口返回泛型的问题(System.InvalidCastException: 无法将类型为“System.Collections.Generic.List`1[System.String]”的对象强制转换为类型“System.String[]”)
在使用C#写Web Service时遇到了个很奇怪的问题.返回值的类型是泛型(我用的是类似List<string>)的接口,测试时发现总是报什么无法转换为对象的错误,百思不得其解. 后来在 ...
- 无法将类型为“System.DBNull”的对象强制转换为类型“System.String”
在ERP中做业务类单据,有时候会遇到这样的报错. 无法将类型为"System.DBNull"的对象强制转换为类型"System.String" 去数据库中检 ...
- C# 无法将类型为“__DynamicallyInvokableAttribute”的对象强制转换为类型...
错误代码: //遍历方法特性 foreach (MethodInfo m in type.GetMethods()) { foreach(Attribute a in m.GetCustomAttri ...
- 如何解决”无法将类型为“System.DateTime”的对象强制转换为类型“System.String”。“
字段Time在数据库中为datetime类型 dr.GetString(3).ToString() dr.GetString(3).ToString() => dr.GetDateTime(3) ...
随机推荐
- 匿名对象和object的转换
有时候经常用到需要把一个匿名对象存入session或List<object>或其他容器中,可是取出来的时候变成object了,不太方便使用. 下面是一种转换方式: class Pr ...
- Difference between Satisfiable, Valid, Unsatisfiable & Invalid
A formula is satisfiable if it is possible to find an interpretation (model) that makes the formula ...
- Windows下修改Oracle默认的端口1521
数据库最好不对公网开放,如果要开放,最好把默认端口改掉,防止一些针对 1521端口的入侵 1.找到 product\11.2.0\dbhome_1\NETWORK\ADMIN 下面的 listene ...
- 项目管理知识体系指南(PMBOOK指南)(第5版) 阅读摘要
1.7.2 项目经理的人际技能 领导力: 团队建设: 激励: 沟通: 影响力: 决策能力: 政治和文化意识: 谈判: 建立信任: 冲突管理: 教练技术: 3.4 规划过程组 在制定项目管理计划和项目文 ...
- SAP顾问发展
关于SAP顾问发展的话题也不仅仅是一次的谈起,但是我想对于自己的规划很多人是否有没有深刻的考虑过.这对于你我来说都非常的重要,那么作为我来说,我仅仅把自己的观点阐述以供大家思考,希望对大家能有所帮助. ...
- spring中bean配置和bean注入
1 bean与spring容器的关系 Bean配置信息定义了Bean的实现及依赖关系,Spring容器根据各种形式的Bean配置信息在容器内部建立Bean定义注册表,然后根据注册表加载.实例化Bean ...
- 制作便携版 FireFox 火狐浏览器
Firefox是一款可高度自定义的开源浏览器: 你可以访问 火狐DIY 定制自己的Firefox安装包, 此外,你还可以自己动手定制一款可以放在U盘随身携带的便携版Firefox火狐浏览器. 制作便携 ...
- struts2 using kindeditor upload pictures (including jmagic compressed images)
Project uses a kindeditor3.4 UploadContentImgAction @SuppressWarnings("serial") @ParentPac ...
- React Native Android增加本地图片
将图片文件 UePbdph.png 放入与index.android.js的同目录中,在index.android.js中引入: <Image source={require('./UePbdp ...
- 当应用程序不是以 UserInteractive 模式运行时显示模式对话框或窗体是无效操作
在Web程序中引用了WinForm的类库引起了 主要是为了在web程序中使用Message.Show()以及SaveFileDialog类,能web程序中引用了WinForm类库 在Visual St ...