c# - DataGridView doesn't update when assigning datasource of second datagrid -
i have 2 datagridviews 1 displayed. both have same columns different values. problem 1 displayed , when select first or second datagridview, datagridview showing someting, stops , doesn't work @ anymore.
i tried this
datagridview1 = datagridview2;
like this
bindingsource b = new bindingsource(); b.datasource = datagridview2.datasource; datagridview1.datasource = null; datagridview1.datasource = b; datagridview1.visible = true; datagridview1.autogeneratecolumns = true;
but nothing working... , yes, tried update()
, refresh()
you can verify application of following simple example
namespace gridview { public partial class form1 : form { public form1() { initializecomponent(); dataset ds= new dataset(); ds.readxml(@"c:\users\user\desktop\students.xml"); datagridview1.autogeneratecolumns = true; datagridview1.datasource = ds; datagridview1.datamember = "student"; application.doevents(); } private void form1_load(object sender, eventargs e) { bindingsource b = new bindingsource(); datagridview2.autogeneratecolumns = true; b.datasource = datagridview1.datasource; datagridview2.datamember = "student"; datagridview2.datasource = b; } } }
i think miss datamember attribute assign datasource of grid 1 grid 2 , works me also.
Comments
Post a Comment