Share via

DataColumn.Caption Property


Gets or sets the caption for the column.

 property System::String ^ Caption { System::String ^ get(); void set(System::String ^ value); };
public string Caption { get; set; }
public string Caption { get; set; }
member this.Caption : string with get, set
member this.Caption : string with get, set
Public Property Caption As String

Property Value

The caption of the column. If not set, returns the ColumnName value.



The following example creates a new DataTable. It then adds three DataColumn objects to a DataColumnCollection and sets the Caption property for each DataColumn.

private void CreateDataTable()
   DataTable table;
   DataColumn column;

   table = new DataTable("Customers");

   //CustomerID column
   column = table.Columns.Add("CustomerID",
   column.Unique = true;
   //CustomerName column
   column = table.Columns.Add("CustomerName",
   column.Caption = "Name";

   column = table.Columns.Add("CreditLimit",
   column.DefaultValue = 0;
   column.Caption = "Limit";

   table.Rows.Add(new object[] {1, "Jonathan", 23.44});
   table.Rows.Add(new object[] {2, "Bill", 56.87});
Private Sub CreateDataTable()
    Dim table As DataTable
    Dim column As DataColumn 

    table = new DataTable("Customers")

    'CustomerID column
    column = table.Columns.Add( _
        "CustomerID", System.Type.GetType("System.Int32"))
    column.Unique = True

    'CustomerName column
    column = table.Columns.Add( _
        "CustomerName", System.Type.GetType("System.String"))
    column.Caption = "Name"

    column = table.Columns.Add( _
        "CreditLimit", System.Type.GetType("System.Double"))
    column.DefaultValue = 0
    column.Caption = "Limit"

    table.Rows.Add(new object() {1, "Jonathan", 23.44})
    table.Rows.Add(new object() {2, "Bill", 56.87})
End Sub


You can use the Caption property to display a descriptive or friendly name for a DataColumn.

Applies to

See also