如何在C#中的datagridview上显示字符串? [英] How to show string on datagridview in C# ?
本文介绍了如何在C#中的datagridview上显示字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在C#中使用LINQ。
IList< string> student = new List< string>(){abc,xyz,pqr};
var result =来自学生选择s中的s;
datagridview .datasource =结果;
此代码无法正常工作。
我想表现出敬意datagridview。
任何人都可以帮助我吗?...请
我尝试了什么:
我尝试了各种方法。但是我没有得到正确的结果。
I'm using LINQ in C#.
IList<string> student=new List<string>(){"abc","xyz","pqr"};
var result = from s in student select s;
datagridview.datasource=result;
this code isn't working.
I want to show reult on datagridview.
Can any one help me?...please
What I have tried:
I have tried various method. But I don't get proper result.
推荐答案
它没有工作,因为字符串的唯一属性是Length,而DataGridView使用属性来决定什么显示。
您可以做的是将您的字符串封装在另一个类中:
It doesn;t work because the only property for a string is the Length, and a DataGridView uses properties to decide what to display.
What you can do is encapsulate your string in another class:
List<string> student = new List<string>() { "abc", "xyz", "pqr" };
var result = student.Select(s => new { value = s }).ToList();
myDataGridView.DataSource = result;
可行。
这篇关于如何在C#中的datagridview上显示字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文