Click here to Skip to main content
15,880,427 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using a WPF DataGrid with AutoGenerateColumns set to true and setting the items source to a List of (Integer). Rows are created in the DataGrid for each item in the List of (Integer) but nothing is displayed in the rows. I am pretty sure this relates to the items source for the DataGrid need to be dependency properties or public properties. I would think there would be a simple way to get a list of T or even a simple array of Integers to display in a WPF DataGrid without having to create a custom class with a Public Integer Property, then making a collection of that class and setting the DataGrid items source to that class. Is there a simpler way to do display a list simple data types like integers without having to use a custom class.
Posted
Comments
[no name] 3-Apr-13 12:28pm    
There is no reason to create a custom class.

1 solution

This seems like a straig forward way to do it using lambdas:
http://stackoverflow.com/questions/479329/how-to-bind-a-string-list-to-a-datagrid/479419#479419[^]

C#
IList<String> list_string= new List<String>();
DataGridView.DataSource = list_string.Select(x => new { Value = x }).ToList();
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 3-Apr-13 13:50pm    
Sure, a 5.
—SA

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