DataGridColumnStyle.HeaderText 属性

定义

获取或设置列标题的文本。Gets or sets the text of the column header.

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

属性值

作为列标题显示的字符串。A string that is displayed as the column header. 如果它是由 DataGrid 创建的,则默认值是用于创建该列的 PropertyDescriptor 的名称。If it is created by the DataGrid, the default value is the name of the PropertyDescriptor used to create the column. 如果它是由用户创建的,则默认值是一个空的字符串 ("")。If it is created by the user, the default is an empty string ("").

示例

下面的代码示例将HeaderText属性设置为一个新值。The following code example sets the HeaderText property to a new value.

void SetHeaderText()
{
   DataGridColumnStyle^ dgCol;
   DataColumn^ dataCol1;
   DataTable^ dataTable1;
   dgCol = dataGrid1->TableStyles[ 0 ]->GridColumnStyles[ 0 ];
   dataTable1 = dataSet1->Tables[ dataGrid1->DataMember ];
   dataCol1 = dataTable1->Columns[ dgCol->MappingName ];
   dgCol->HeaderText = dataCol1->Caption;
}

private void SetHeaderText()
{
    DataGridColumnStyle dgCol;
    DataColumn dataCol1;
    DataTable dataTable1;
    dgCol = dataGrid1.TableStyles[0].GridColumnStyles[0];
    dataTable1 = dataSet1.Tables[dataGrid1.DataMember];
    dataCol1 = dataTable1.Columns[dgCol.MappingName];
    dgCol.HeaderText = dataCol1.Caption;
}
 
Private Sub SetHeaderText()
    Dim dgCol As DataGridColumnStyle
    Dim dataCol1 As DataColumn
    Dim dataTable1 As DataTable
    dgCol = dataGrid1.TableStyles(0).GridColumnStyles(0)
    dataTable1 = dataSet1.Tables(dataGrid1.DataMember)
    dataCol1 = dataTable1.Columns(dgCol.MappingName)
    dgCol.HeaderText = dataCol1.Caption
End Sub

注解

当值不易理解时MappingName HeaderText MappingName ,属性通常用于显示与值不同的标题。The HeaderText property is typically used to display a caption that is different from the MappingName value when the MappingName value isn't easily understandable. 例如, HeaderText MappingName当值为 "FName" 时,可以将更改为 "First Name"。For example, you can change the HeaderText to "First Name" when the MappingName value is "FName".

适用于

另请参阅