3

My DataGrid receives data from a DataView in the following way:

myDataGrid.ItemsSource = myDataTable.AsDataView();

This works fine. However, the name of one of the columns has the "/" character. And the result is as follows:

ABCD    DEFG     HIJ/K    LMNO

34      7554              4234
52      7358              5454
12      3458              234
23      2345              1254

So the cells of the column with "/" are empty. This seems to be some binding problem.

According to this article, the slash is a reserved character in binding path.

What can I do to fix this?

I really need to use AutoGenerateColumns, because I don't know exactly the input data (the user can dynamically change it).

Edit

What to do to solve any issue related to this (and others reserved characters):

XAML

<DataGrid x:Name="dtgResult" AutoGenerateColumns="True" AutoGeneratingColumn="dtgResult_AutoGeneratingColumn" >

C#

private void dtgResult_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
{
    if (e.Column is DataGridBoundColumn)
    {
        DataGridBoundColumn dataGridBoundColumn = e.Column as DataGridBoundColumn;
        dataGridBoundColumn.Binding = new Binding("[" + e.PropertyName + "]");
    }
}
Guilherme
  • 5,143
  • 5
  • 39
  • 60
  • I think the right direction would be to represent the column header as `HIJ/K` but actually naming the column `HIJK` (or whatever). Not sure if/how it is applicable with DataView, though. – SimpleVar Aug 29 '14 at 17:53

0 Answers0