WPF Datagrid binding and column display

前端 未结 3 2102
死守一世寂寞
死守一世寂寞 2021-01-04 01:33

I have datatable as Item source for DataGrid, this datatable has lots of columns. Is it possible to display few columns instead all of them without creating a new table?

3条回答
  •  误落风尘
    2021-01-04 02:21

    Yes, Yes very much. If your Table structure and Column Name remains constant then in Datagrid XAML set AutoGenerateColums = False and manually create all columns.

    
     
      
      
     
    
    

    and then in codebehind simple provide Source like

    mydg.ItemSource = Data.DefaultView;
    

    Now when your DataTable contains column FirstColumnName and SecondColumnName they will be databound to your Datagrid.

提交回复
热议问题