PDA

Click to See Complete Forum and Search --> : DataGrid problem?


kia_q5
Nov 20th, 2002, 11:42 PM
I have a problem in my DataGrid.

How to change the Column Header Text and Column Width?

Serge
Dec 2nd, 2002, 04:52 PM
Here you go:


DataTable tblData = (DataTable)dataGrid1.DataSource;

DataGridTableStyle tsMyStyle = new DataGridTableStyle();
tsMyStyle.MappingName = "MyTable"; //MappingName should match the name of the table


DataGridColumnStyle TextCol = new DataGridTextBoxColumn();
TextCol.MappingName = "Column1"; //MappingName should match the name of the column
TextCol.HeaderText = "New Name of the Column";
TextCol.Width = 125;
tsMyStyle.GridColumnStyles.Add(TextCol);

TextCol = new DataGridTextBoxColumn();
TextCol.MappingName = "Column2"; //MappingName should match the name of the column
TextCol.HeaderText = "Column2"; //leave the same name
TextCol.Width = 50;
tsMyStyle.GridColumnStyles.Add(TextCol);

dataGrid1.TableStyles.Add (tsMyStyle);