'DataGridView' VS 'DataGrid' when Convert to 'DataSet'?
I bound excel data with DataGridView controller successfully. Then I try to save the DataGridView contents to xml file. I want to implement as belwo, but throw exception. How can I fix it using DataGridView? (VS2008 used)
// I tried to implement using this style.But throw exception.
DataSet ds = (DataSet)(dataGridView1.DataSource);
// One onl开发者_如何学JAVAine tutorial posted as this style below
DataSet ds = (DataSet)(dataGrid1.DataSource);
Using a breakpoint in the debugger, check what class type dataGridView1.DataSource
actually is.
For instance, you might find that if you are using a BindingSource
class between the grid view and the data set, that the views data source is not a DataSet
, but instead a System.Data.DataView
which wraps the DataSet
.
You would then have to use:
DataSet ds = ((DataView)dataGridView1.DataSource).Table.DataSet;
精彩评论