Data is visible in DataSet visualizer but does not show in a DataGrid

后端 未结 1 1302
小鲜肉
小鲜肉 2020-11-27 08:18

my code is

public DataTable Load_to_DataGrid(string Line_ID)
{
    con.ConnectionString = ConfigurationManager.ConnectionStrings[1].ConnectionString;
    c         


        
相关标签:
1条回答
  • 2020-11-27 08:49

    When DataGrid generates columns for its ItemsSource, it uses DataTable column names as binding path for columns. While / symbol is valid in DataColumn names, in has a special meaning in binding path and should be escaped if it is a part of name, e.g. [80/4] not 80/4

    add event handler to AutoGeneratingColumn event in xaml:

    AutoGeneratingColumn="Dg_OnAutoGeneratingColumn"
    

    and modify bindings with this code:

    private void Dg_OnAutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
    {
        var textCol = e.Column as DataGridTextColumn;
        if (textCol == null)
            return;
        var binding = textCol.Binding as Binding;
        if (binding == null)
            return;
        binding.Path = new PropertyPath("[" + binding.Path.Path + "]");
    }
    
    0 讨论(0)
提交回复
热议问题