I had this Question For long time until now. I made an Extension Method for this.
For BindingSource Filled With Data From Database.
This Code Will Clone The Structure And Will Copy The Data. With No Bind Between them.
and fast.
edit: Now You Can Copy Just Filtered Rows.
public static BindingSource Clone(
this BindingSource bindingSource,
bool justFiltered)
{
try
{
DataTable tbl, tbl2;
if (justFiltered)
{
var dv =
((System.Data.DataTable)bindingSource.DataSource).DefaultView;
dv.RowFilter = bindingSource.Filter;
tbl = dv.ToTable();
tbl2 = tbl.Copy();
}
else
{
tbl = (DataTable)bindingSource.DataSource;
tbl2 = tbl.Copy();
}
BindingSource newBindingSource =
new BindingSource(tbl2, bindingSource.DataMember);
return newBindingSource;
}
catch
{
}
return null;
}