如何在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;

可行。