DataColumn.Caption 属性

定义

获取或设置列的标题。

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

属性值

列的标题。 如果没有设置,则返回 ColumnName 的值。

属性

示例

以下示例创建新的 DataTable。 然后,它将三 DataColumn 个 对象添加到 , DataColumnCollection 并为每个 设置 Caption 属性 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

注解

可以使用 Caption 属性来显示 的描述性名称或友好名称 DataColumn

适用于

另请参阅