cast datagrid.datasource to dataset (datasource is table)

  • Thread starter Thread starter newsgroper
  • Start date Start date
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.
 
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
 
Back
Top