Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to force datagrid to display DataColumn caption in column header

How to force datagrid to display DataColumn caption in column header

Scheduled Pinned Locked Moved C#
tutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AndrusM
    wrote on last edited by
    #1

    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

    L 1 Reply Last reply
    0
    • A AndrusM

      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

      L Offline
      L Offline
      Lisa Jorgensen
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups