D
David Veeneman
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.Caption 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.Tables["Investments"];
for (int i = 0; i < gridInvestments.ColumnCount; i++)
{
gridInvestments.Columns.HeaderText =
myDataset.Tables["Investments"].Columns.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
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.Caption 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.Tables["Investments"];
for (int i = 0; i < gridInvestments.ColumnCount; i++)
{
gridInvestments.Columns.HeaderText =
myDataset.Tables["Investments"].Columns.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