471,325 Members | 1,643 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,325 software developers and data experts.

Help with DataGridTableStyle?

I have the following DataGridTableStyle:

DataGridTableStyle gridTableStyle = new DataGridTableStyle();
gridTableStyle.MappingName = "myStyle";
DataGridTextBoxColumn dgsc = new DataGridTextBoxColumn();
dgsc.MappingName = "FirstName";
dgsc.HeaderText = "First Name";
dgsc.Width = 30;
dgsc.TextBox.Enabled = false;
gridTableStyle.GridColumnStyles.Add(dgsc);

mygrid.TableStyles.Add(gridTableStyle);
mygrid.DataSource = someDataView;

I can see in the grid for the assigned table that the firstname column
is "FirstName". That should match. Instead, every row from the
DataSet shows in the grid. Shouldn't only the firstname column
display? What am I doing wrong?

Thanks,
Brett

Jan 11 '06 #1
4 5699
Actually, I just needed to change this
gridTableStyle.MappingName = "myStyle";

to the actual table name coming from the DataSource.

Brett

Jan 11 '06 #2
Brett,

I don't think that you need to set the MappingName property on the table
style. The mapping name is for when you are binding to a specific type, not
for the name of the table, I believe.

From the documentation for the MappingName property:

To bind the DataGrid to a strongly typed array of objects, the object type
must contain public properties. To create a DataGridTableStyle that displays
the array, set the DataGridTableStyle.MappingName property to typename where
typename is replaced by the name of the object type. Also note that the
MappingName property is case-sensitive; the type name must be matched
exactly. See the MappingName property for an example.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Brett Romero" <ac*****@cygen.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
I have the following DataGridTableStyle:

DataGridTableStyle gridTableStyle = new DataGridTableStyle();
gridTableStyle.MappingName = "myStyle";
DataGridTextBoxColumn dgsc = new DataGridTextBoxColumn();
dgsc.MappingName = "FirstName";
dgsc.HeaderText = "First Name";
dgsc.Width = 30;
dgsc.TextBox.Enabled = false;
gridTableStyle.GridColumnStyles.Add(dgsc);

mygrid.TableStyles.Add(gridTableStyle);
mygrid.DataSource = someDataView;

I can see in the grid for the assigned table that the firstname column
is "FirstName". That should match. Instead, every row from the
DataSet shows in the grid. Shouldn't only the firstname column
display? What am I doing wrong?

Thanks,
Brett

Jan 11 '06 #3
/*You Need to Add only the required Column to a DataTable and then bind
that to the grid. */

dgsc.ColumnName = "FirstName";
/*Then you should add this Column to the Binding table*/
DataTable SomeDataTable = new DataTable();
SomeDataTable.Columns.Add(dgsc);

/*then */

mygrid.DataSource = SomeDataTable;
HTH

Jan 11 '06 #4
Brett,
You can suppress the display of a column with (example)

ds.Tables("Products").Columns("QuantityPerUnit").C olumnMapping =
MappingType.Hidden

--Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Brett Romero" wrote:
I have the following DataGridTableStyle:

DataGridTableStyle gridTableStyle = new DataGridTableStyle();
gridTableStyle.MappingName = "myStyle";
DataGridTextBoxColumn dgsc = new DataGridTextBoxColumn();
dgsc.MappingName = "FirstName";
dgsc.HeaderText = "First Name";
dgsc.Width = 30;
dgsc.TextBox.Enabled = false;
gridTableStyle.GridColumnStyles.Add(dgsc);

mygrid.TableStyles.Add(gridTableStyle);
mygrid.DataSource = someDataView;

I can see in the grid for the assigned table that the firstname column
is "FirstName". That should match. Instead, every row from the
DataSet shows in the grid. Shouldn't only the firstname column
display? What am I doing wrong?

Thanks,
Brett

Jan 11 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Scott | last post: by
2 posts views Thread by Brett Romero | last post: by
reply views Thread by Familjen Karlsson | last post: by
3 posts views Thread by nita | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.