DataGridView.ColumnHeadersBorderStyle DataGridView.ColumnHeadersBorderStyle DataGridView.ColumnHeadersBorderStyle DataGridView.ColumnHeadersBorderStyle Property

定義

列ヘッダーに適用された境界線スタイルを取得します。Gets the border style applied to the column headers.

public:
 property System::Windows::Forms::DataGridViewHeaderBorderStyle ColumnHeadersBorderStyle { System::Windows::Forms::DataGridViewHeaderBorderStyle get(); void set(System::Windows::Forms::DataGridViewHeaderBorderStyle value); };
[System.ComponentModel.Browsable(true)]
public System.Windows.Forms.DataGridViewHeaderBorderStyle ColumnHeadersBorderStyle { get; set; }
member this.ColumnHeadersBorderStyle : System.Windows.Forms.DataGridViewHeaderBorderStyle with get, set
Public Property ColumnHeadersBorderStyle As DataGridViewHeaderBorderStyle

プロパティ値

例外

このプロパティの設定時に指定した値が、有効な DataGridViewHeaderBorderStyle 値ではありません。The specified value when setting this property is not a valid DataGridViewHeaderBorderStyle value.

このプロパティの設定時に指定された値が Custom です。The specified value when setting this property is Custom.

ColumnHeadersBorderStyle、、、 AutoSizeRowsMode 、、ColumnCount、、、、 ColumnHeadersDefaultCellStyleおよびの各プロパティを設定する方法を次のコード例に示します。BackgroundColor GridColor CellBorderStyle RowHeadersVisible SelectionMode MultiSelectThe following code example demonstrates how to set the ColumnHeadersDefaultCellStyle, AutoSizeRowsMode, ColumnHeadersBorderStyle, CellBorderStyle, GridColor, BackgroundColor, RowHeadersVisible, SelectionMode, ColumnCount, and MultiSelect properties. また、このコード例は、プロパティDataGridViewColumn.NameDataGridViewColumn.DefaultCellStyleプロパティを設定する方法を示しています。In addition, the code example demonstrates how to set the DataGridViewColumn.Name and DataGridViewColumn.DefaultCellStyle properties. この例を実行するにはDataGridView 、という名前dataGridView1のを含むフォームにコードを貼り付けてから、フォームのコンストラクターまたLoadはイベントハンドラーからメソッドをSetUpDataGridView呼び出します。To run this example, paste the code into a form that contains a DataGridView nameddataGridView1, and then call the SetUpDataGridView method from the form's constructor or Load event handler. すべてのイベントがイベントハンドラーに関連付けられていることを確認します。Ensure all events are associated with their event handlers.

void SetUpDataGridView()
{
   this->Controls->Add( dataGridView1 );
   dataGridView1->ColumnCount = 5;
   DataGridViewCellStyle^ style = dataGridView1->ColumnHeadersDefaultCellStyle;
   style->BackColor = Color::Navy;
   style->ForeColor = Color::White;
   style->Font = gcnew System::Drawing::Font( dataGridView1->Font,FontStyle::Bold );
   dataGridView1->EditMode = DataGridViewEditMode::EditOnEnter;
   dataGridView1->Name = "dataGridView1";
   dataGridView1->Location = Point(8,8);
   dataGridView1->Size = System::Drawing::Size( 500, 300 );
   dataGridView1->AutoSizeRowsMode = DataGridViewAutoSizeRowsMode::DisplayedCellsExceptHeaders;
   dataGridView1->ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle::Raised;
   dataGridView1->CellBorderStyle = DataGridViewCellBorderStyle::Single;
   dataGridView1->GridColor = SystemColors::ActiveBorder;
   dataGridView1->RowHeadersVisible = false;
   dataGridView1->Columns[ 0 ]->Name = "Release Date";
   dataGridView1->Columns[ 1 ]->Name = "Track";
   dataGridView1->Columns[ 1 ]->DefaultCellStyle->Alignment = DataGridViewContentAlignment::MiddleCenter;
   dataGridView1->Columns[ 2 ]->Name = "Title";
   dataGridView1->Columns[ 3 ]->Name = "Artist";
   dataGridView1->Columns[ 4 ]->Name = "Album";

   // Make the font italic for row four.
   dataGridView1->Columns[ 4 ]->DefaultCellStyle->Font = gcnew System::Drawing::Font( DataGridView::DefaultFont,FontStyle::Italic );
   dataGridView1->SelectionMode = DataGridViewSelectionMode::FullRowSelect;
   dataGridView1->MultiSelect = false;
   dataGridView1->BackgroundColor = Color::Honeydew;
   dataGridView1->Dock = DockStyle::Fill;
   dataGridView1->CellFormatting += gcnew DataGridViewCellFormattingEventHandler( this, &Form1::dataGridView1_CellFormatting );
   dataGridView1->CellParsing += gcnew DataGridViewCellParsingEventHandler( this, &Form1::dataGridView1_CellParsing );
   addNewRowButton->Click += gcnew EventHandler( this, &Form1::addNewRowButton_Click );
   deleteRowButton->Click += gcnew EventHandler( this, &Form1::deleteRowButton_Click );
   ledgerStyleButton->Click += gcnew EventHandler( this, &Form1::ledgerStyleButton_Click );
   dataGridView1->CellValidating += gcnew DataGridViewCellValidatingEventHandler( this, &Form1::dataGridView1_CellValidating );
}
private void SetUpDataGridView()
{
    this.Controls.Add(dataGridView1);
    dataGridView1.ColumnCount = 5;
    DataGridViewCellStyle style = 
        dataGridView1.ColumnHeadersDefaultCellStyle;
    style.BackColor = Color.Navy;
    style.ForeColor = Color.White;
    style.Font = new Font(dataGridView1.Font, FontStyle.Bold);

    dataGridView1.EditMode = DataGridViewEditMode.EditOnEnter;
    dataGridView1.Name = "dataGridView1";
    dataGridView1.Location = new Point(8, 8);
    dataGridView1.Size = new Size(500, 300);
    dataGridView1.AutoSizeRowsMode = 
        DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders;
    dataGridView1.ColumnHeadersBorderStyle = 
        DataGridViewHeaderBorderStyle.Raised;
    dataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.Single;
    dataGridView1.GridColor = SystemColors.ActiveBorder;
    dataGridView1.RowHeadersVisible = false;

    dataGridView1.Columns[0].Name = "Release Date";
    dataGridView1.Columns[1].Name = "Track";
    dataGridView1.Columns[1].DefaultCellStyle.Alignment = 
        DataGridViewContentAlignment.MiddleCenter;
    dataGridView1.Columns[2].Name = "Title";
    dataGridView1.Columns[3].Name = "Artist";
    dataGridView1.Columns[4].Name = "Album";

    // Make the font italic for row four.
    dataGridView1.Columns[4].DefaultCellStyle.Font = new Font(DataGridView.DefaultFont, FontStyle.Italic);

    dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
    dataGridView1.MultiSelect = false;

    dataGridView1.BackgroundColor = Color.Honeydew;

    dataGridView1.Dock = DockStyle.Fill;

    dataGridView1.CellFormatting += new DataGridViewCellFormattingEventHandler(dataGridView1_CellFormatting);
    dataGridView1.CellParsing += new DataGridViewCellParsingEventHandler(dataGridView1_CellParsing);
    addNewRowButton.Click += new EventHandler(addNewRowButton_Click);
    deleteRowButton.Click += new EventHandler(deleteRowButton_Click);
    ledgerStyleButton.Click += new EventHandler(ledgerStyleButton_Click);
    dataGridView1.CellValidating += new DataGridViewCellValidatingEventHandler(dataGridView1_CellValidating);

}
Private Sub SetUpDataGridView()

    Me.Controls.Add(dataGridView1)
    dataGridView1.ColumnCount = 5

    With dataGridView1.ColumnHeadersDefaultCellStyle
        .BackColor = Color.Navy
        .ForeColor = Color.White
        .Font = New Font(dataGridView1.Font, FontStyle.Bold)
    End With

    With dataGridView1
        .EditMode = DataGridViewEditMode.EditOnEnter
        .Name = "dataGridView1"
        .Location = New Point(8, 8)
        .Size = New Size(500, 300)
        .AutoSizeRowsMode = _
            DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders
        .ColumnHeadersBorderStyle = _
            DataGridViewHeaderBorderStyle.Raised
        .CellBorderStyle = _
            DataGridViewCellBorderStyle.Single
        .GridColor = SystemColors.ActiveBorder
        .RowHeadersVisible = False

        .Columns(0).Name = "Release Date"
        .Columns(1).Name = "Track"
        .Columns(1).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        .Columns(2).Name = "Title"
        .Columns(3).Name = "Artist"
        .Columns(4).Name = "Album"

        ' Make the font italic for row four.
        .Columns(4).DefaultCellStyle.Font = _
            New Font(Control.DefaultFont, _
                FontStyle.Italic)

        .SelectionMode = _
            DataGridViewSelectionMode.FullRowSelect
        .MultiSelect = False

        .BackgroundColor = Color.Honeydew

        .Dock = DockStyle.Fill
    End With

End Sub

注釈

プロパティがSingle以外GridColorの値に設定されている場合、プロパティはシステムカラーである必要があります。 ColumnHeadersBorderStyleIf the ColumnHeadersBorderStyle property is set to anything other than Single, the GridColor property must be a system color.

このプロパティをCustom値に設定することはできません。この値は、 AdvancedColumnHeadersBorderStyleプロパティを使用して境界線スタイルがカスタマイズされていることを示す読み取り専用の値です。You cannot set this property to the Custom value, which is a read-only value indicating that the border style has been customized through the use of the AdvancedColumnHeadersBorderStyle property.

注意

Application.EnableVisualStylesメソッドを使用してアプリケーションに対して visual スタイルが有効EnableHeadersVisualStylesになっtrueていて、プロパティがの場合は、現在のテーマを使用して列ヘッダーが描画されます。If visual styles are enabled for the application through the Application.EnableVisualStyles method and the EnableHeadersVisualStyles property is true, the column headers are painted using the current theme. この場合、テーマが適用されColumnHeadersBorderStyleていないをTopLeftHeaderCell除くすべての列ヘッダーに対して、プロパティの値は無視されます。In this case, the value of the ColumnHeadersBorderStyle property is ignored for all column headers except the TopLeftHeaderCell, to which the theme is not applied.

適用対象

こちらもご覧ください