Pregunta

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

¿Fue útil?

Solución

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top