DataColumn.Caption Property
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets or sets the caption for the column.
public:
property System::String ^ Caption { System::String ^ get(); void set(System::String ^ value); };
public string Caption { get; set; }
[System.Data.DataSysDescription("DataColumnCaptionDescr")]
public string Caption { get; set; }
member this.Caption : string with get, set
[<System.Data.DataSysDescription("DataColumnCaptionDescr")>]
member this.Caption : string with get, set
Public Property Caption As String
The caption of the column. If not set, returns the ColumnName value.
- Attributes
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",
System.Type.GetType("System.Int32"));
column.Unique = true;
//CustomerName column
column = table.Columns.Add("CustomerName",
System.Type.GetType("System.String"));
column.Caption = "Name";
//CreditLimit
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});
}
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"
'CreditLimit
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.
Product | Versions |
---|---|
.NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: