By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,083 Members | 2,237 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,083 IT Pros & Developers. It's quick & easy.

Trying to link DataGrideTableStyle to DataGrid

P: n/a
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);
Nov 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi,

"scott" <sc***********@hotmail.com> wrote in message
news:dj**********@news6.svr.pol.co.uk...
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);

Nov 17 '05 #2

P: n/a
Thank you for your quick responce and fix.

It all works now.
"Bart Mermuys" <bm*************@hotmail.com> wrote in message
news:ul**************@tk2msftngp13.phx.gbl...
Hi,

"scott" <sc***********@hotmail.com> wrote in message
news:dj**********@news6.svr.pol.co.uk...
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);


Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.