How to Bind a DataGrid to a DataTable all in code behind?

后端 未结 2 1574
醉梦人生
醉梦人生 2021-01-15 13:33

How to bind a DataGrid to a DataTable in C# code behind? (All controls are generated in run-time, so no XAML please)

I tried Binding(), set the DataContext, set the

2条回答
  •  长发绾君心
    2021-01-15 14:37

    Also, to keep a good abstraction layer between your data and its representation on your forms, I would suggest you to set the property AutoGenerateColumns of your DataGridView to false and add just the columns you want displayed by hand, with the header name of your choice (in this case, do not forget to set the columns' DataPropertyName property).

提交回复
热议问题