I'm trying to add 2 datasets to one datagridview.

for example, dataset1 is filled with datatable1 and dataset2 is filled with datatable2.

I use this to add dataset1 to my datagridview :

datagridview.Datasource = dataset1.Tables[0];    

Now I want to add datset2 to the datagridview without clearing data that it contains.

the name of columns in both datatables are same.

Can anyone help me????

Regards

有帮助吗?

解决方案

You can try merging your data tables like following:

DataTable datasource = dataset1.Tables[0];
datasource.Merge(dataset2.Tables[0]);

datagridview.Datasource = datasource;

this can also work:

((DataTable)datagridview.Datasource).Merge(dataset2.Tables[0])

and then refresh the grid view

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top