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 4 5847
Actually, I just needed to change this
gridTableStyle. MappingName = "myStyle";
to the actual table name coming from the DataSource.
Brett
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
/*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
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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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 " +
|
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...
|
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...
|
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.
| |
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...
|
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...
|
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
|
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;
|
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,...
|
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...
| |
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...
|
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...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
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...
| |