Export (0) Print
Expand All

DataColumn.Caption Property

Gets or sets the caption for the column.

[Visual Basic]
Public Property Caption As String
[C#]
public string Caption {get; set;}
[C++]
public: __property String* get_Caption();
public: __property void set_Caption(String*);
[JScript]
public function get Caption() : String;
public function set Caption(String);

Property Value

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

Remarks

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

Example

[Visual Basic, C#, C++] The following example creates a new DataTable. It then adds three DataColumn objects to a DataColumnCollection and sets the Caption property for each DataColumn.

[Visual Basic] 
Private Sub CreateDataTable()
    Dim dt As DataTable
    Dim dc As DataColumn 

    dt = new DataTable("Customers")

    'CustomerID column
    dc = dt.Columns.Add( "CustomerID", System.Type.GetType( "System.Int32" ) )
    dc.Unique = True
    
    'CustomerName column
    dc = dt.Columns.Add( "CustomerName", System.Type.GetType( "System.String" ) )
    dc.Caption = "Name"

    'CreditLimit
    dc = dt.Columns.Add( "CreditLimit", System.Type.GetType( "System.Double" ) )
    dc.DefaultValue = 0
    dc.Caption = "Limit"

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

[C#] 
private void CreateDataTable()
{
   DataTable dt;
   DataColumn dc;

   dt = new DataTable("Customers");

   //CustomerID column
   dc = dt.Columns.Add( "CustomerID", System.Type.GetType( "System.Int32" ) );
   dc.Unique = true;
    
   //CustomerName column
   dc = dt.Columns.Add( "CustomerName", System.Type.GetType( "System.String" ) );
   dc.Caption = "Name";

   //CreditLimit
   dc = dt.Columns.Add( "CreditLimit", System.Type.GetType( "System.Double" ) );
   dc.DefaultValue = 0;
   dc.Caption = "Limit";

   dt.Rows.Add( new object[] {1, "Jonathan", 23.44} );
   dt.Rows.Add( new object[] {2, "Bill",     56.87} );
}

[C++] 
private:
void CreateDataTable()
{
   DataTable* dt;
   DataColumn* dc;

   dt = new DataTable(S"Customers");

   //CustomerID column
   dc = dt->Columns->Add( S"CustomerID", System::Type::GetType( S"System.Int32" ) );
   dc->Unique = true;
    
   //CustomerName column
   dc = dt->Columns->Add( S"CustomerName", System::Type::GetType( S"System.String" ) );
   dc->Caption = S"Name";

   //CreditLimit
   dc = dt->Columns->Add( S"CreditLimit", System::Type::GetType( S"System.Double" ) );
   dc->DefaultValue = 0;
   dc->Caption = S"Limit";

   Object* temp0 [] = {__box(1), S"Jonathan", __box(23.44)};
   dt->Rows->Add( temp0 );

   Object* temp1 [] = {__box(2), S"Bill", __box(56.87)};
   dt->Rows->Add( temp1 );
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

DataColumn Class | DataColumn Members | System.Data Namespace | ColumnName

Show:
© 2014 Microsoft