c# - Winform clone DataGridViewRow along with DataBoundItem -
i have list of pocos this:
list<a> alist; public class { public string m { get; set; } public string n { get; set; } public bs list<b> { get; set; } } public class b { public string x { get; set; } public string y { get; set; } } i can bind datagridview dgv no problem. want clone row, along copy of a in row.
var row = dgv.selectedcells[0].owningrow; var alist= (list<a>)((bindingsource)dgv.datasource).datasource; var = (a)row.databounditem; var clone = (datagridviewrow)row.clone(); //only copied blank row, no content dgv.rows.add(clone); var copya = (a)clone.databounditem; as.add(copya); // 'copya' null, because databouditem not copied. how make happen clone row has clone data?
i prefer simpe work around, not going notifypropertychanged, bindinglist , if possible?
add new "row" in data instead binded datagridview.
var currentcell = dgv.currentcell; var bs = (bindingsource)dgv.datasource; var data = (list<a>)bs.datasource; var currentselection = (a)row.databounditem; data.add(currentselection); bs.resetbindings(false); // should refresh grid dgv.currentcell = currentcell; // put current cell
Comments
Post a Comment