문제

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