How can I set a bound DataGridView control to use a dataset table's column
captions, instead of column names?
I'm working with a DataGridView control, which I have bound to a table in a
dataset. The dataset is created at run time, so I don't know column headers
in advance. The table's column captions are set at run time, using the
DataColumn.Capt ion property. The table is bound to the grid using the grid's
DataSource property. Here is my problem: The grid displays column names,
rather than captions, as it's header text.
Right now, I'm inserting the captions using a loop:
// Initialize Investments grid
gridInvestments .DataSource = myDataset.Table s["Investment s"];
for (int i = 0; i < gridInvestments .ColumnCount; i++)
{
gridInvestments .Columns[i].HeaderText =
myDataset.Table s["Investment s"].Columns[i].Caption;
}
I'm looking for a simpler way to get the job done.
Is there a DataGridView property that will tell the grid to get column
headers from the DataColumns' Caption property, rather than the Name
property? Thanks in advance
--
David Veeneman
Foresight Systems. 2 9688
David,
That's pretty much the way I would do it. Unfortunately, the binding
mechanism is pretty generic (using reflection and implemented interfaces to
get this information). This mechanism, however, does not have any way for
the data source to expose the column header information (after all, you can
bind to anything that implements IList).
What you have is fine.
If anything, you could derive a class from DataGridView which will do
this for you.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"David Veeneman" <da****@nospam. com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. .. How can I set a bound DataGridView control to use a dataset table's column captions, instead of column names?
I'm working with a DataGridView control, which I have bound to a table in a dataset. The dataset is created at run time, so I don't know column headers in advance. The table's column captions are set at run time, using the DataColumn.Capt ion property. The table is bound to the grid using the grid's DataSource property. Here is my problem: The grid displays column names, rather than captions, as it's header text.
Right now, I'm inserting the captions using a loop:
// Initialize Investments grid gridInvestments .DataSource = myDataset.Table s["Investment s"]; for (int i = 0; i < gridInvestments .ColumnCount; i++) { gridInvestments .Columns[i].HeaderText = myDataset.Table s["Investment s"].Columns[i].Caption; }
I'm looking for a simpler way to get the job done.
Is there a DataGridView property that will tell the grid to get column headers from the DataColumns' Caption property, rather than the Name property? Thanks in advance
-- David Veeneman Foresight Systems.
Thanks--and thanks for the prompt response! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Bob |
last post by:
Thinking two things,
1- Creating a userControl -yeah you guessed it, a multi column drop down
combobox - I've looked at several articles and did not find what I need, one
that's bindable and that I can use in a datagrid view.
2- Extending the datagridview so that it can be added to the list in the
column types when editing columns in the datagridview.
I'm really getting PO'd at Microsoft for not including a multi column
combobox both a...
|
by: mark carew |
last post by:
Hi,
Problem - An extra column to the left (even with row headers disabled)
----------------------------------------------------------
Apologies if this posting is already in the newsgroup; but have changed to
40tude and can't see it in the newly dowloaded messages. It was originally
html (tut tut) so maybe it didn't register. I have tried a new xml file and
generated a new xsd file from it using xsd.exe and now the xml file
produces...
|
by: Mike |
last post by:
Dear group,
I'm currrently investigating a bug within a piece of our software whereby if
a DataGridView (bound directly to a DataTable) is ordered by column headers
(containing lookup combo boxes where the value is the foreign key of another
table), although the DataGridView is ok, the DataTable becomes out of sync.
In other words, I have a Grid of customers, and if a customer name column
header is clicked - the data moves in the...
|
by: =?Utf-8?B?TG9zdEluTUQ=?= |
last post by:
Hi All :)
I'm converting VB6 using True DBGrid Pro 8.0 to VB2005 using DataGridView.
True DBGrid has a MultipleLines property that controls whether individual
records span multiple lines. Is there an equivalent property for the
DataGridView? I have searched, but have not found one.
I would like the user to be able to see all the columns of the table on one
screen - thus eliminating the need to use the horizontal scroll bar to view...
|
by: =?Utf-8?B?VHJlY2l1cw==?= |
last post by:
Hello, Newsgroupians:
I'm creating a control derived from DataGridView. I'd like the user to
click a row and have the row highlight in yellow. I'd then like the user to
click a column and have the column highlight in yellow. Where the row and
column intersect, I'd like the cell to take on a red color. It's synonymous
to a grid matrix for many maps... EXA:
How many miles from one city to another:
| |
by: TG |
last post by:
Hi!
I have an application in which I have some checkboxes and depending
which ones are checked those columns will show in the datagridview
from sql server or no.
After that I have 2 buttons:
1) export to excel button exports the visible columns from the
datagridview to excel (this works fine)
|
by: Steve |
last post by:
Hi All
I am using VB.net 2005 windows forms
I use the Datagridview.cellformatting event to change the colours of
individual cells as required and all works fine
How can I do the same for the datagridview column headers?
I would like to change the forecolor value for individual column headers as
required, so the Headertext displays in the required colour
|
by: theamesy |
last post by:
I have a datagridview on a windows form, AllowUserToResizeColumns is
set to false, it has 3 columns, as you'd expect i cant resize the
columns, but i CAN resize the last column?
I have column headers visible set to true, and i can drag the far end
of the final column back n forwards.
If i set column headers visible to false, then i have the ability to
drag from the area where the rows are!
|
by: =?Utf-8?B?QWxleCBLLg==?= |
last post by:
Hi all
No matter how hard I try, I cannot force my DataGridView to use specific
font in column headers: it seems to be always the same as container's font
(which is form in my case).
I set styles:
ColumnHeadersDefaultCellStyle
DefaultCellStyle
and even
|
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...
|
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: 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: 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,...
|
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: 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...
|
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: 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...
| |