Problem with AutoGenerateColumns = "true" and DataView binding when column name has /

My DataGrid gets data from DataView like this:

myDataGrid.ItemsSource = myDataTable.AsDataView();

      

This works great. However, the name of one of the columns has a "/" 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 column cells with "/" are empty. It seems to be some kind of binding issue.

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

What can I do to fix this?

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

Edit

What to do to solve any problem with this (and other reserved characters):

XAML

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

      

FROM#

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 + "]");
    }
}

      

+3


source to share





All Articles