473,597 Members | 2,829 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with DataGridTableSt yle?

I have the following DataGridTableSt yle:

DataGridTableSt yle gridTableStyle = new DataGridTableSt yle();
gridTableStyle. MappingName = "myStyle";
DataGridTextBox Column dgsc = new DataGridTextBox Column();
dgsc.MappingNam e = "FirstName" ;
dgsc.HeaderText = "First Name";
dgsc.Width = 30;
dgsc.TextBox.En abled = false;
gridTableStyle. GridColumnStyle s.Add(dgsc);

mygrid.TableSty les.Add(gridTab leStyle);
mygrid.DataSour ce = 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 5838
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 DataGridTableSt yle that displays
the array, set the DataGridTableSt yle.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.co m

"Brett Romero" <ac*****@cygen. com> wrote in message
news:11******** **************@ g49g2000cwa.goo glegroups.com.. .
I have the following DataGridTableSt yle:

DataGridTableSt yle gridTableStyle = new DataGridTableSt yle();
gridTableStyle. MappingName = "myStyle";
DataGridTextBox Column dgsc = new DataGridTextBox Column();
dgsc.MappingNam e = "FirstName" ;
dgsc.HeaderText = "First Name";
dgsc.Width = 30;
dgsc.TextBox.En abled = false;
gridTableStyle. GridColumnStyle s.Add(dgsc);

mygrid.TableSty les.Add(gridTab leStyle);
mygrid.DataSour ce = 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.C olumns.Add(dgsc );

/*then */

mygrid.DataSour ce = SomeDataTable;
HTH

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

ds.Tables("Prod ucts").Columns( "QuantityPerUni t").ColumnMappi ng =
MappingType.Hid den

--Peter

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


"Brett Romero" wrote:
I have the following DataGridTableSt yle:

DataGridTableSt yle gridTableStyle = new DataGridTableSt yle();
gridTableStyle. MappingName = "myStyle";
DataGridTextBox Column dgsc = new DataGridTextBox Column();
dgsc.MappingNam e = "FirstName" ;
dgsc.HeaderText = "First Name";
dgsc.Width = 30;
dgsc.TextBox.En abled = false;
gridTableStyle. GridColumnStyle s.Add(dgsc);

mygrid.TableSty les.Add(gridTab leStyle);
mygrid.DataSour ce = 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
5128
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? Also, how can I associate all the attributes and their values of a particular element to the Name & Value columns of a datatable - to read into a datatable as well as write from the datatable to the xml element? Any help will be greatly...
4
7031
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. Basically, what I want to do is that, on a button click, the dataset fills up dynamically, binds to the datagrid, and displays the data. This is my code: mySql = "select itemID, OrderDate " +
8
3124
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 and bind these data to my datagrid in the form, when I click the button first time, it work fine. but when I click the second button. it report belowing error, I guess it is because it already set up the column name at first time, so cann't do...
0
3630
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 datagrid on the left side that lists names and perhaps a couple of other key fields. The user can click on a record in the datagrid, which should automatically pull up details on that record in the various text boxes and other controls on the right...
2
3111
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 does not seem to be working.
4
1901
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 don't see a way to do this through the datagrid properties. I am not using a database connection, I just want to set column headers on the datagrid. I am somewhat new to vb.net. Here is the code I am using. This code works when the...
2
2412
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 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...
0
1302
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 work. Explain what I have to do to make that work. Fia Imports System Imports System.Windows.Forms
3
4271
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 great. The problem is the columns are in the wrong order. OK. I'll use the datagridtablestyle. But when I add the following statement; Dim tableStyle As New DataGridTableStyle I get an error when I build the project;
0
7967
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7885
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8272
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8381
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8031
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8258
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5847
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
2403
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1233
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.