.NET/C# 绑定 IList<string>到 DataGridView [英] .NET / C# Binding IList&lt;string&gt; to a DataGridView

查看:32
本文介绍了.NET/C# 绑定 IList<string>到 DataGridView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从函数返回的 IList(作为变量 lst),我设置然后我

I have an IList<string> returning from a function (as variable lst) and I set and then I

this.dataGridView1.DataSource = lst;

数据网格添加一列标有长度的列,然后列出每个字符串的长度.我如何让它只列出字符串?

The datagrid adds one column labelled Length and then lists the length of each string. How do I make it just list the strings?

推荐答案

您确实需要一个具有字符串属性的对象列表.使用 .NET 3.5,您可能会作弊:

You really need a list of objects that have a string property. With .NET 3.5 you could cheat:

.DataSource = list.Select(x=>new {Value = x}).ToList();

否则创建一个虚拟类并手动复制数据...

Otherwise create a dummy class and copy the data in manually...

这篇关于.NET/C# 绑定 IList<string>到 DataGridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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