cast datagrid.datasource to dataset (datasource is table)

N

newsgroper

I extended a windows datagrid to some formatting and to add controls
like buttons and comboboxes. To get the datagrid to accept the
changes I add tablestyles. To make the datagrid use the new
tablestyles and bind to the table I used the following code...

this.TableStyles.Clear();
this.TableStyles.Add(_tableStyle);
this.DataSource = ((DataSet)this.DataSource).Tables[tableName];

Everything works great! However, now my form needs to access the
grids datasource as a dataset like so...

theDataSet.Update((DataSet)theGrid.DataSource);

Unfortunately, I get an invalid cast exception since the datasource is
a datatable. Can anyone give me suggestions so I can update the
dataset that was originally bound to my grid? I know the problem is
because I bound the table to the grid (within the grid's code) when I
extended the grid. I am just not sure how to get the datasource back
to a dataset.
 
P

Palo Mraz

theDataSet.Update((DataSet)theGrid.DataSource);
DataSet doesn't expose Update method. What is the type of the theDataSet
variable?

A solution seems to be simple (maybe I don't understand you explanation:):

theDataSet.Update(((DataTable)theGrid.DataSource).DataSet)

Palo
http://www.vbinfozine.com - Real world entertaining information for Visual
Basic developers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top