0
votes

I try to set up a Datagrid in wpf. To fill it out I use a DataTable. The problem is that if I want to create a new Column, I can't set the name from a List of string variables, because the Coloumn header will be wrong placed and I can't add values to the rows under the Column. In code:

datatable.Columns.Add(new DataColumn("Test", typeof(string)));//This works

datatable.Columns.Add(new DataColumn(stringlist[i], typeof(string)));//This doesn't work

This illustration shows the wrong placement:

enter image description here

1
I didn't get the question. Could you please precise what is the list of string variables for? why don't you use xaml binding for the list? - Maxim Fleitling
the list of strings is entered by the users and has each time a different length and different values. Now the list should represent the names of the columns of the datagrid. I've never took a look at xaml binding. - user5636721

1 Answers

1
votes

I would suggest you trim any white space that the user may accidentally enter before/after the name, like this:

datatable.Columns.Add(new DataColumn(stringlist[i].Trim(), typeof(string)));