Trying to link DataGrideTableStyle to DataGrid

S

scott

Hi all

First off, thank you for any one that can help.

I have a problem trying to link a DataGrideTableStyle to a DataGrid.

I have a dataset which reads from a file a xml schema and a xml file. This
is done using the ReadXmlSchema and ReadXml.

I then create a DataTable to get access to the tables in the data set.

I then use the DataTable to get one of the tables (there are 2 tables it
holds) and use the DataGride.SetDataBinding to link the datagrid to the
table. It is at this point the error occurs saying

An Unhandled exception of type 'System.ArgumentException' occurred in
System.windows.forms.dll

Additional information: Cannot create a child list for field ShoppintItem.

From what I have been reading I need to use the SetDataBinding because when
I come to use a DataGrideTableStyle that tablestyle needs to be linked using
its MappingName to the dataGrid's DataMember.

I am doing all this so that in the datagride I can hide/Delete some columns
that I don't want to show up.

Below is the code I am using.

Thx for taking the time to read this and help.

Scott.


ds = new DataSet();

ds.ReadXmlSchema(@"C:\Document and Settings. . . . . ");
ds.ReadXml(@"C:\Documents and Settings . . . . ");

System.Data.DataTable dt = new DataTable();

// just checking they are there
string tn = ts.Tables[0].TableName;
string TN = ds.Tables[1].TableName;

System.Data.DataTable DT = ds.Tables[1];

dataGrid1.SetDataBinding(DT, DT.TableName); // <--- Error occurs here.

System.Windows.Forms.DataGridTableStle ts = new DataGrideTableStyle();
ts.MappingName = dataGrid1.DataMember;
DataGrid1.TableStyles.Add(ts);
 
B

Bart Mermuys

Hi,

scott said:
Hi all

First off, thank you for any one that can help.

I have a problem trying to link a DataGrideTableStyle to a DataGrid.

I have a dataset which reads from a file a xml schema and a xml file. This
is done using the ReadXmlSchema and ReadXml.

I then create a DataTable to get access to the tables in the data set.

I then use the DataTable to get one of the tables (there are 2 tables it
holds) and use the DataGride.SetDataBinding to link the datagrid to the
table. It is at this point the error occurs saying

An Unhandled exception of type 'System.ArgumentException' occurred in
System.windows.forms.dll

Additional information: Cannot create a child list for field
ShoppintItem.

From what I have been reading I need to use the SetDataBinding because
when
I come to use a DataGrideTableStyle that tablestyle needs to be linked
using
its MappingName to the dataGrid's DataMember.

I am doing all this so that in the datagride I can hide/Delete some
columns
that I don't want to show up.

Below is the code I am using.

Thx for taking the time to read this and help.

Scott.


ds = new DataSet();

ds.ReadXmlSchema(@"C:\Document and Settings. . . . . ");
ds.ReadXml(@"C:\Documents and Settings . . . . ");

System.Data.DataTable dt = new DataTable();

// just checking they are there
string tn = ts.Tables[0].TableName;
string TN = ds.Tables[1].TableName;

System.Data.DataTable DT = ds.Tables[1];

dataGrid1.SetDataBinding(DT, DT.TableName); // <--- Error occurs here.

It is either :
dataGrid1.SetDataBinding(DT, "");
-or-
dataGrid1.SetDataBinding(ds, DT.TableName);

You could also use dataGrid1.DataSource/DataMember in the same way.
System.Windows.Forms.DataGridTableStle ts = new DataGrideTableStyle();
ts.MappingName = dataGrid1.DataMember;

No, it needs to be the name of the table (which can but doesn't need to be
the same as the DataMember)
ts.MappingName = DT.TableName;


HTH,
Greetings
 
S

scott

Thank you for your quick responce and fix.

It all works now.


Bart Mermuys said:
Hi,

scott said:
Hi all

First off, thank you for any one that can help.

I have a problem trying to link a DataGrideTableStyle to a DataGrid.

I have a dataset which reads from a file a xml schema and a xml file. This
is done using the ReadXmlSchema and ReadXml.

I then create a DataTable to get access to the tables in the data set.

I then use the DataTable to get one of the tables (there are 2 tables it
holds) and use the DataGride.SetDataBinding to link the datagrid to the
table. It is at this point the error occurs saying

An Unhandled exception of type 'System.ArgumentException' occurred in
System.windows.forms.dll

Additional information: Cannot create a child list for field
ShoppintItem.

From what I have been reading I need to use the SetDataBinding because
when
I come to use a DataGrideTableStyle that tablestyle needs to be linked
using
its MappingName to the dataGrid's DataMember.

I am doing all this so that in the datagride I can hide/Delete some
columns
that I don't want to show up.

Below is the code I am using.

Thx for taking the time to read this and help.

Scott.


ds = new DataSet();

ds.ReadXmlSchema(@"C:\Document and Settings. . . . . ");
ds.ReadXml(@"C:\Documents and Settings . . . . ");

System.Data.DataTable dt = new DataTable();

// just checking they are there
string tn = ts.Tables[0].TableName;
string TN = ds.Tables[1].TableName;

System.Data.DataTable DT = ds.Tables[1];

dataGrid1.SetDataBinding(DT, DT.TableName); // <--- Error occurs here.

It is either :
dataGrid1.SetDataBinding(DT, "");
-or-
dataGrid1.SetDataBinding(ds, DT.TableName);

You could also use dataGrid1.DataSource/DataMember in the same way.
System.Windows.Forms.DataGridTableStle ts = new DataGrideTableStyle();
ts.MappingName = dataGrid1.DataMember;

No, it needs to be the name of the table (which can but doesn't need to be
the same as the DataMember)
ts.MappingName = DT.TableName;


HTH,
Greetings

DataGrid1.TableStyles.Add(ts);
 

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