How to force datagrid to display DataColumn caption in column header
-
The following code shows "Column1" as column caption. Why ? How to force DataGrid to display "Caption" as column caption ? using System.Windows.Forms; using System.Data; static class Program { static void Main() { Application.Run(new Frm()); } } class Frm : Form { public Frm() { DataTable dt = new DataTable(); DataColumn column = new DataColumn(); column.Caption = "Caption"; dt.Columns.Add(column); DataGrid dg= new DataGrid(); this.Controls.Add(dg); dg.SetDataBinding(dt, ""); } } Andrus
-
The following code shows "Column1" as column caption. Why ? How to force DataGrid to display "Caption" as column caption ? using System.Windows.Forms; using System.Data; static class Program { static void Main() { Application.Run(new Frm()); } } class Frm : Form { public Frm() { DataTable dt = new DataTable(); DataColumn column = new DataColumn(); column.Caption = "Caption"; dt.Columns.Add(column); DataGrid dg= new DataGrid(); this.Controls.Add(dg); dg.SetDataBinding(dt, ""); } } Andrus
The DataGrid uses the DataColumn's ColumnName as the column caption. The ColumnName defaults to Column1, Column2, etc., so that's why the code shows "Column1" as the caption. If you set the DataColumn's ColumnName to "Caption", then that will be the caption displayed in the DataGrid.