使用LINQ从CheckedListBox.CheckedItems创建一个字符串集合 [英] Create a string collection from CheckedListBox.CheckedItems using LINQ

查看:188
本文介绍了使用LINQ从CheckedListBox.CheckedItems创建一个字符串集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用了Entity框架来填充一个检查的列表框。我想要将检查的项目的名称作为字符串集合,以便它们可以用作另一个LINQ查询的过滤器。

I have used the Entity framework to populate a checked list box. I want to get the names of the checked items as a string collection so that they can then be used as a filter for another LINQ query.

我填充列表框,如这个...

I populate the list box like this...

_eventTypesCheckedList.DataSource = this._dataContext.tblEventTypes.OrderBy(ev => ev.EventTypeName);
_eventTypesCheckedList.DisplayMember = "EventTypeName";

这是我无法获取字符串集合...

This is how I'm failing to get the string collection...

var types = from eType in ((_eventTypesCheckedList.CheckedItems) as IEnumerable< tblEventType > )
            select new string( eType.EventTypeName.ToCharArray() );

任何帮助都会很棒。

推荐答案

使用 .Cast< Type>()扩展方法转换 CheckItems

_eventTypesCheckedList.CheckedItems.Cast<tblEventType>()

这篇关于使用LINQ从CheckedListBox.CheckedItems创建一个字符串集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆