button - sending data from 1 data grid view to another data grid view in another form c# -




the following method used me send rows data grid view in form(datagridview1 of form1) data grid view of form(datagridview1 of form2) when button clicked.

     private void button2_click(object sender, eventargs e)         {            form2 f2 = new form2();             datatable dt1 = new datatable();             f2.datagridview1.datasource = dt1;              foreach (datagridview row in datagridview1.rows)             {                 int n = f2.datagridview1.rows.add();                 foreach (datagridviewcolumn col in datagridview1.columns)                 {                     f2.datagridview1.rows[n].cells[col.index].value = datagridview1.rows[row.index].cells[col.index].value.tostring();  }             }          } 

but no data sent datagridview1 of form2! how can correct this?

depending on circumstances, i'd work data source, i.e. way

vb.net

dim dt new datatable dt = ds.tables(0)  me.datagridview1.datasource = dt  form2.datagridview2.datasource = dt 

c#

datatable dt = new datatable(); dt = ds.tables(0);  this.datagridview1.datasource = dt;  form2.datagridview2.datasource = dt; 

if wanted modify 1 of them independently, need second datatatable:

dim dt2 new datatable dt2 = dt.copy()   ' copies datatable structure , data form2.datagridview2.datasource = dt 




wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -