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

適用於

另請參閱