0
votes

I have a WPF project in which I wanted to display some data in a Datagrid. I have a class which is given below.

   public class Demo
   {
       public string ColunmHeader{ get; set; } 
       private List<string> values = new List<string>();
   }

I have List which I need to bind to Datagrid columns. The ColunmHeader property should be the name of datagrid column and the List of values should be shown under the column header. How can I bind the List Values to datagrid columns?

1
Do you want to display values in a single column? - Dennis
Yes.For each ColumHeader values will be visible under this. - Aron
So, why do you need a DataGrid with a single column? Why don't display values in a ListBox? - Dennis
Actually I need a dynamic datagrid which will generate the columns according to the List<Demo>. something like this. var data =new List<Demo>(); for (int i = 0; i < data.Count; i++) { { DataGrd.Columns.Add(new DataGridTextColumn { Header = data[i].Name }); } } - Aron
Please, add your .xaml code. - Sonhja

1 Answers

0
votes

You need to bind a list of "models" to the datagrid.

e.g.

public class Example
{
     public String Value { get; set;}

}


List<Example> list = new List<Example>():

The column headers will be the name of the property.