473,396 Members | 1,780 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,396 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 5816
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Anita C | last post by:
Hi, How do I associate or map a specific column in a datatable to a particular element present in an xml document - to read into a datatable as well as write from the datatable to the xml element?...
4
by: John | last post by:
Hello all, I'm trying to display a dataset into a datagrid and format the datagrid columns but I'm having a hard time with it. I've tried the MSDN examples but they don't seem to work. ...
8
by: pei_world | last post by:
Hi, there; I have a problem with my datagrid control. I declared it in one of my form, set with DataGridTalbeStyle as well, and when I click on button, I would like to retrive Data from Database...
0
by: Patrick | last post by:
I'm working on a contact management application, and need a hand with one aspect... Here's what I want to create: ------------------------------------ A form split into two parts. There is a...
2
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...
4
by: Jeff | last post by:
I am stuck on trying to generate two columns headers for a datagrid on form load. I can use a datatable as the datasource and get the results I want, but I want to set different column widths and...
2
by: Brett Romero | last post by:
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...
0
by: Familjen Karlsson | last post by:
Hi I have downloaded some code and tried it and nothing happens with the datagrid. Explain what is wrong and what I have to do please. I have tried to Import the namespace Hamster and it didn't...
3
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...
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.