DataView Question

G

Guest

Hello,

I have a situation that I wish some help with. I have a DataSet object with DataTables populated from a ms access database. Each DataTable has a RunLogTitle. I have a TreeView object with TreeNodes that correspods to the Names of each DataTable's RunLogTitle. When the user clicks on a TreeNode the corresponding DataTable shows up in the DataGrid.

This is working great, but I would want to use a DataView object to show only the components of each DataTable in the DataGrid. I am using a DataGridTableStyle object to then create DataGridColumnStyles.

Here is the problem, in the DataGridTableStyle I have set the MappingName to a DataView object that I have created in the constructor, here is the code that appears in the constructor of the class:
this.myDataView = new DataView(new DataTable);
this.MyDataView.Table.TableName = "MyDataView";

When the form opens up, the DataGrid is populated with the appropriate DataView and the appropriate DataGridColumnStyles only showing the data I wish to show up. HOwever when I click on a different TreeNode, I get an error message stating that "MyDataView" already belongs to the DataSet.

I have been going nuts on trying to solve this, how can I set the DataView to show the other DataTale without getting this message? This is the best way that I can describe this problem, if anyone out there can help me with this I'll greatly appreicate it!

thanks,
ed
 
B

Branimir Giurov

Hi there,

what you need is not to set the table name every time, but simply assign the
new one to the dataGridTableStyle's mapping name right after setting the new
datasource.

dataGrid1.DataSource = new DataView(dataTable2, ....);
dataGridTableStyle1.MappingName = dataTable2.TableName;

This should work.

Good luck,
Branimir

--
Branimir Giurov
MCSD.NET, MCDBA
www.sofiadev.org



Ed_P. said:
Hello,

I have a situation that I wish some help with. I have a DataSet object
with DataTables populated from a ms access database. Each DataTable has a
RunLogTitle. I have a TreeView object with TreeNodes that correspods to the
Names of each DataTable's RunLogTitle. When the user clicks on a TreeNode
the corresponding DataTable shows up in the DataGrid.
This is working great, but I would want to use a DataView object to show
only the components of each DataTable in the DataGrid. I am using a
DataGridTableStyle object to then create DataGridColumnStyles.
Here is the problem, in the DataGridTableStyle I have set the MappingName
to a DataView object that I have created in the constructor, here is the
code that appears in the constructor of the class:
this.myDataView = new DataView(new DataTable);
this.MyDataView.Table.TableName = "MyDataView";

When the form opens up, the DataGrid is populated with the appropriate
DataView and the appropriate DataGridColumnStyles only showing the data I
wish to show up. HOwever when I click on a different TreeNode, I get an
error message stating that "MyDataView" already belongs to the DataSet.
I have been going nuts on trying to solve this, how can I set the DataView
to show the other DataTale without getting this message? This is the best
way that I can describe this problem, if anyone out there can help me with
this I'll greatly appreicate it!
 
G

Guest

Thanks Branimir! I'll give this a try!

Branimir Giurov said:
Hi there,

what you need is not to set the table name every time, but simply assign the
new one to the dataGridTableStyle's mapping name right after setting the new
datasource.

dataGrid1.DataSource = new DataView(dataTable2, ....);
dataGridTableStyle1.MappingName = dataTable2.TableName;

This should work.

Good luck,
Branimir

--
Branimir Giurov
MCSD.NET, MCDBA
www.sofiadev.org




with DataTables populated from a ms access database. Each DataTable has a
RunLogTitle. I have a TreeView object with TreeNodes that correspods to the
Names of each DataTable's RunLogTitle. When the user clicks on a TreeNode
the corresponding DataTable shows up in the DataGrid.
only the components of each DataTable in the DataGrid. I am using a
DataGridTableStyle object to then create DataGridColumnStyles.
to a DataView object that I have created in the constructor, here is the
code that appears in the constructor of the class:
DataView and the appropriate DataGridColumnStyles only showing the data I
wish to show up. HOwever when I click on a different TreeNode, I get an
error message stating that "MyDataView" already belongs to the DataSet.
to show the other DataTale without getting this message? This is the best
way that I can describe this problem, if anyone out there can help me with
this I'll greatly appreicate it!
 

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