473,389 Members | 1,367 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,389 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 2398
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Carlos | last post by:
Does DataGridTableStyle work in ASP.net ? any time I'm tring to define a varibale lke DataGridTableStyle MyStyle = new DataGridTableStyle(); it give me "The Type or name sapce...
by: Scott | last post by:
Hi all. A few days ago i ask this question and got a good quick response. I tried out what they said and it worked. However I have now come to try the same thing in another program and it...
by: Carlos | last post by:
Does DataGridTableStyle work in ASP.net ? any time I'm tring to define a varibale lke DataGridTableStyle MyStyle = new DataGridTableStyle(); it give me "The Type or name sapce...
by: kerpal | last post by:
Hi all, 1. Could anyone pls clarify the difference between setting the AlternatingBackColor property in DataGridTableStyle and in DataGrid?? 2. How come BackColor and AlternatingBackColor are...
by: Brett Romero | last post by:
I have the following DataGridTableStyle: DataGridTableStyle gridTableStyle = new DataGridTableStyle(); gridTableStyle.MappingName = "myStyle"; DataGridTextBoxColumn dgsc = new...
by: Brett Romero | last post by:
When I create this table and add it to my DataGrid (framework v1.1), the TableStyle works fine: DataTable dt = new DataTable(); DataColumn dc = new DataColumn("AreaCode"); DataColumn dctwo =...
by: nita | last post by:
I'm just starting out, and it's incredibly frustrating when I see sample code and then try to implement it. Case in point. I'm populating a collection then binding it to a datagrid. That works...
by: Mitchell S. Honnert | last post by:
Is there an equivalent of the DataGrid's DataGridTableStyle for the DataGridView? If not, is there an easy way to duplicate the DataGridTableStyle's functionality for the DataGridView? Here's...
by: Guillaume | last post by:
Hi, I have an ArrayList filled with many Alarm object ( i will ad next this class definition). I use this arraylist as a datasource for my datagrid. I want to apply some table style, but it does...
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.