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...
https://www.czetsuyatech.com/2021/07/c-change-datagrid-header.html
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];




2 comments
Hi your code works fine except for one change in the code.
Add style.MappingName="table name";
This is working!
Hi, yes your right forgot to paste that part.
Again this part is very important:
style.MappingName="table name";
Thanks :-D
Post a Comment