no

How to Change the Datagrid Column Header

Using .Net1.1, I experienced a problem on how I could change the header text of a datagrid. Normally, you can set it like this (using the Da...

Using .Net1.1, I experienced a problem on how I could change the header text of a datagrid. Normally, you can set it like this (using the DataGridTableStyle):

DataSet ds = query("Select field_name from table");
datagrid.DataSource = ds.Tables[0];

//and NAME will be displayed as the datagrid's headertext.

DataGridTableStyle style = new DataGridTableStyle();
DataGridColumnStyle colStyle = new DataGridTextBoxColumn();
colStyle.HeaderText = "NAME";
colStyle.MappingName = "field_name";
style.GridColumnStyles.Add(colStyle);
datagrid.TableStyles.Add(style);

//Unfortunately it's not working. 
//An alternative is to rename the column in the sql query:


DataSet ds = query("Select field_name AS NEW_FIELD_NAME from table");
datagrid.DataSource = ds.Tables[0];

Related

c# 8593764382271269235

Post a Comment Default Comments

2 comments

Unknown said...

Hi your code works fine except for one change in the code.

Add style.MappingName="table name";

This is working!

czetsuya said...

Hi, yes your right forgot to paste that part.

Again this part is very important:

style.MappingName="table name";

Thanks :-D

item