I have a datagrid which is binded to a datatable. Now I wish to add a column to this datagrid. the values are stored in a dictionary. I wish to add values to columns from this d开发者_高级运维ictionary. How can I add column with values to either the datagrid or to the datatable?
There are two solution
- Edit your DataTable and add a field that represent the column you wish to add, then fill it programatically.
- The second solution is to add a column to the data grid through the designer and then iterate through the data grid cells and fill the values from code-behind.
I personally prefer the first solution, its more clean.
To edit you DataTable follow the following steps:
Now you can iterate through your DataTable object from code behind and add the values for each row :D
精彩评论