Why don't DataGrid Use DataColumn.Caption

M

madhu

I found following thread
source :-
http://www.dotnet247.com/247reference/msgs/16/84118.aspx
-----------------------------------------------------------
-----------------
I need to change the caption of a DataColumn and I wrote
this but it doesn't
work

DataSet ds = new DataSet();
sqlDataAdapter1.Fill(ds,"Orders");
ds.Tables[0].Columns[0].Caption = "NEW CAPTION";
dataGrid1.SetDataBinding(ds,"Orders");

instead this code work
ds.Tables[0].Columns[0].ColumnName = "NEW CAPTION";

why ?

thank Paps
-----------------------------------------------------------
-----------------
Hi Paps,

Did you want to change the DataGrid's column caption? When
binding a
DataTable to DataGrid, it will use the ColumnName of a
dataColumn as its
column caption in DataGrid.

Luke
-----------------------------------------------------------
-----------------
Hi Luke

So if I need to change the DataGrid column Caption I need
to change the
DataSet.Tables[0].Columns[0].ColumnName and not the
Caption ?
But in this way I loose consistence with my dataSoruce ?

Thanks Paps
-----------------------------------------------------------
-----------------
Hello Paps,
There seems to be an issue with datagrid where it does not
use the caption
property to set the header text for the columns.
I was able to get around that by creating my own
datagridtablestyle and
datagridcolumnstyle and setting the headertext properties.

Dim ts1 As New DataGridTableStyle()
ts1.MappingName = "Items"
Dim TextCol3 As New DataGridTextBoxColumn()
TextCol3.MappingName = "Description"
TextCol3.HeaderText = "Item Description"
TextCol3.TextBox.ForeColor = System.Drawing.Color.Brown
TextCol3.Width = 150
ts1.GridColumnStyles.Add(TextCol3)
MyDataGrid.TableStyles.Add(ts1)

Hope this helps.
Ramesh Thyagarajan
Microsoft Developer support
-----------------------------------------------------------
------
However there is lot of headache if we have to use
DataGridTableStyle to save changing the DataColumn's
column names. If there are lot of grids in project which
is very common situation this is really cumbersome task.
Also there is maintenance issue, simple addition or
removal of some column in display compels you to work on
both DAL and GUI layer. Can we avoid this in some decent
way so that we get best of both worlds, I mean I don't
need to loose the consistency of column names with
datasource while using DataColumn and also I don't need to
do extra work IN GUI layer.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top