471,355 Members | 1,666 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Why doesn't DataGridTableStyle work?

I can't find what exactly I'm doing wrong that the following
DataGridTableStyle is not working on my table. The result set returns
21 columns. I'm only formatting 5 via the TableStyle. I thought maybe
the problem was I had more columns being put into the DataGrid than I
was formatting. I then created a new table and adding only the five
mapped columns to it. That didn't help either.

I'm hiding column 3 because I need its value but don't want it
displayed. I do get the five columns output into the grid but no
styling. Any suggestions:

DataTable dt = new DataTable();

DataGridTableStyle participantGridTableStyle = new
participantGridTableStyle.MappingName = dt.TableName;

// Create GridColumnStyle objects for the grid columns
//First five columns are: PersonId, PersonCode, FirstName,
MiddleName, LastName

DataGridTextBoxColumn partCol1 = new DataGridTextBoxColumn();
DataGridTextBoxColumn partCol2 = new DataGridTextBoxColumn();
DataGridTextBoxColumn partCol3 = new DataGridTextBoxColumn();
DataGridTextBoxColumn partCol4 = new DataGridTextBoxColumn();
DataGridTextBoxColumn partCol5 = new DataGridTextBoxColumn();

partCol1.MappingName = "PersonId";
partCol2.MappingName = "PersonCode";

//hide column 3
partCol3.MappingName = "FirstName";
partCol3.Width = 0;

partCol4.MappingName = "MiddleName";

partCol5.MappingName = "LastName";
//just to see if style is outputting
partCol5.HeaderText = "Last | Name";
partCol5.Width = 65;
partCol5.Alignment = HorizontalAlignment.Left;
partCol5.TextBox.Enabled = false;

// Add the GridColumnStyles to the DataGrid's Column Styles
// Place the "ID" column (column 1) last since it is not visible.

participantGridTableStyle.GridColumnStyles.Add(par tCol1);
participantGridTableStyle.GridColumnStyles.Add(par tCol2);
participantGridTableStyle.GridColumnStyles.Add(par tCol3);
participantGridTableStyle.GridColumnStyles.Add(par tCol4);
participantGridTableStyle.GridColumnStyles.Add(par tCol5);

dt = (Searching.FindParticipants()).Tables[0];

//dt.TableName will now be "Table" because of above assignement.
dt.TableName = "ParticipantSearch";

DataTable dtLimit = dt.Copy();;
//restrict to only five columns
int x = 5;
while (x < dtLimit.Columns.Count)

Participant.TableStyles.Add(participantGridTableSt yle);

this.Participant.DataSource = dtLimit;
Participant.NavigateTo(0, dt.TableName);


Dec 15 '05 #1
2 2285
Well I am not sure if this is it or not but....

You have this line:

participantGridTableStyle.MappingName = dt.TableName;

Then later on you have this line:

dt.TableName = "ParticipantSearch";

Which means your DGTS is mapping to a table that doesn't really exist.

Try putting the MappingName assignment lower down.

Steven Nagy

Dec 15 '05 #2
Glad you posted back to this Steven. You are right. The problem was a
combination of what you mentioned and previously this line resetting
the table name.

dt = (Searching.FindParticipants()).Tables[0];

It reset the dt table back to "Table". That's why this line now
follows it.

dt.TableName = "ParticipantSearch";


Dec 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Carlos | last post: by
2 posts views Thread by Scott | last post: by
2 posts views Thread by Carlos | last post: by
4 posts views Thread by Brett Romero | last post: by
9 posts views Thread by Brett Romero | last post: by
3 posts views Thread by nita | last post: by
7 posts views Thread by Mitchell S. Honnert | last post: by
reply views Thread by Guillaume | last post: by
reply views Thread by XIAOLAOHU | 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.