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
c # wpf datatable binding datagrid


source to share


No one has answered this question yet

See similar questions:

eleven
What happens to the dotted DataTable column names that make them unusable for WPF DataGrid control?

or similar:

21
Is there a way to hide a specific column in the DataGrid when AutoGenerateColumns = True?
3
DataGridTemplateColumns, AutoGenerateColumns = true and binding to DataTable
2
how to stop a specific column from being generated in the DataGrid when AutoGenerateColumns is set to True?
2
Wpf-Datagrid and ObservableCollection-AutoGenerateColumns?
1
WPF Datagrid resizes if autogenerateColumns is set to true
0
DataGrid does not bind correctly to DataGrid if AutoGenerateColumns is false
0
Is it possible to add more columns to the DataGrid when AutogenerateColumns == True?
0
DataGrid binding not working with DataView
0
Eliminate WPF DataGrid Binding to DataView with Column Names That Are Invalid as a Property Path
0
MVVM - Hide Datagrid Column Based on Column Name with autogeneratecolumns = True



All Articles
Loading...
X
Show
Funny
Dev
Pics