I'm trying to cast the bindingdatasource to datatable using this code
BindingSource bs = (BindingSource)gvSideMember.DataSource;
DataTable tCxC = (DataTable)bs.DataSource;
throws error unable to cast bindingsource to datatable
then i tried this code
private DataTable GetDataTableFromDGV(DataGridView dgv)
{
var dt = ((DataTable)dgv.DataSource).Copy();
foreach (DataGridViewColumn column in dgv.Columns)
{
if (!column.Visible)
{
dt.Columns.Remove(column.Name);
}
}
return dt;
}
it again show me same error
DataTable dt = new DataTable();
DataSourceSelectArguments args = new DataSourceSelectArguments();
DataView dv = new DataView();
dv = (DataView)SqlDataSource1.Select(args);
dt = dv.ToTable();
but i don't know what is the base class of DataSourceSelectArguments ? So I can't how can i do this cast?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…