开发者

Winforms add column to a databound datagrid

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

  1. Edit your DataTable and add a field that represent the column you wish to add, then fill it programatically.
  2. 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:

Winforms add column to a databound datagrid

Winforms add column to a databound datagrid

Winforms add column to a databound datagrid

Winforms add column to a databound datagrid

Now you can iterate through your DataTable object from code behind and add the values for each row :D

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜