Click here to Skip to main content
15,893,668 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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.
Posted
Updated 26-May-17 1:06am

1 solution

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;
Will work.
 
Share this answer
 
Comments
Member 11091651 26-May-17 8:17am    
Its working...Thanks a lot
OriginalGriff 26-May-17 8:21am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900