title: How to cast bindingdatasource to datatable?
body: <p>I'm trying to cast the bindingdatasource to datatable using this code</p>
  
  <pre><code>BindingSource bs = (BindingSource)gvSideMember.DataSource;
          DataTable tCxC = (DataTable)bs.DataSource;
  </code></pre>
  
  <p>throws error unable to cast bindingsource to datatable</p>
  
  <p>then i tried this code</p>
  
  <pre><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;
      }
  </code></pre>
  
  <p>it again show me same error</p>
  
  <pre><code>  DataTable dt = new DataTable();
          DataSourceSelectArguments args = new DataSourceSelectArguments();
          DataView dv = new DataView();
          dv = (DataView)SqlDataSource1.Select(args);
          dt = dv.ToTable();
  </code></pre>
  
  <p>but i don't know what is the base class of DataSourceSelectArguments ? So I can't how can i do this cast?</p>