DataGridViewCellBorderStyleとは? わかりやすく解説

DataGridView.CellBorderStyle プロパティ

メモ : このプロパティは、.NET Framework version 2.0 で新しく追加されたものです。

DataGridView のセル境界線スタイルを取得します。

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

Public Property CellBorderStyle As
 DataGridViewCellBorderStyle
Dim instance As DataGridView
Dim value As DataGridViewCellBorderStyle

value = instance.CellBorderStyle

instance.CellBorderStyle = value
public DataGridViewCellBorderStyle CellBorderStyle { get;
 set; }
public:
property DataGridViewCellBorderStyle CellBorderStyle {
    DataGridViewCellBorderStyle get ();
    void set (DataGridViewCellBorderStyle value);
}
/** @property */
public DataGridViewCellBorderStyle get_CellBorderStyle ()

/** @property */
public void set_CellBorderStyle (DataGridViewCellBorderStyle
 value)
public function get CellBorderStyle
 () : DataGridViewCellBorderStyle

public function set CellBorderStyle
 (value : DataGridViewCellBorderStyle)

プロパティ値
DataGridView に含まれるセルの境界線スタイルを表す DataGridViewCellBorderStyle。

例外例外
例外の種類条件

InvalidEnumArgumentException

このプロパティの設定時に指定された値が、有効な DataGridViewCellBorderStyle 値ではありません。

ArgumentException

このプロパティの設定時に指定された値は Custom です。

解説解説

CellBorderStyle プロパティが Single、SingleHorizontal、または SingleVertical 以外に設定されている場合、GridColor プロパティはシステム カラーになる必要があります。

このプロパティを Custom 値に設定することはできません。この値は、AdvancedCellBorderStyle プロパティの使用によってセル境界線スタイルがカスタマイズされたことを示す読み取り専用値です。

使用例使用例

CellBorderStyle プロパティを使用する方法を次のコード例に示します。この例を実行するには、dataGridView1 という名前の DataGridView が配置されているフォームにコードを貼り付け、フォームのコンストラクタまたは Load イベント ハンドラから SetUpDataGridView メソッドを呼び出します。必ずすべてのイベントをイベント ハンドラに関連付けるようにしてください。

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
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);

}
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 );
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

DataGridViewCellBorderStyle 列挙体

メモ : この列挙体は、.NET Framework version 2.0 で新しく追加されたものです。

DataGridView コントロールのセルに適用できる境界線スタイルを指定します。

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

Public Enumeration DataGridViewCellBorderStyle
Dim instance As DataGridViewCellBorderStyle
public enum DataGridViewCellBorderStyle
public enum class DataGridViewCellBorderStyle
public enum DataGridViewCellBorderStyle
public enum DataGridViewCellBorderStyle
メンバメンバ
 メンバ名説明
Customカスタマイズされた境界線。 
None境界線なし。 
Raised3D の浮き出した境界線。 
RaisedHorizontal3D の浮き出した水平方向の境界線。 
RaisedVertical3D の浮き出した垂直方向の境界線。 
Single一重線の境界線。  
SingleHorizontal水平方向の一重線の境界線。 
SingleVertical垂直方向の一重線の境界線。 
Sunken3D のくぼんだ境界線。 
SunkenHorizontal3D のくぼんだ水平方向の境界線。 
SunkenVertical3D のくぼんだ垂直方向の境界線。 
解説解説

DataGridView コントロールの CellBorderStyle プロパティは、DataGridViewCellBorderStyle 列挙体を使用します。行の間にのみ境界線を描画するには、SingleHorizontal、SunkenHorizontal、または RaisedHorizontal を指定します。列の間にのみ境界線を描画するには、SingleVertical、SunkenVertical、または RaisedVertical を指定します。行の間と列の間に境界線を描画するには、Single、Sunken、または Raised を指定します。

使用例使用例

この型の使用方法を次のコード例に示します。

Private Sub SetBorderAndGridlineStyles()

    With Me.dataGridView1
        .GridColor = Color.BlueViolet
        .BorderStyle = BorderStyle.Fixed3D
        .CellBorderStyle = DataGridViewCellBorderStyle.None
        .RowHeadersBorderStyle = _
            DataGridViewHeaderBorderStyle.Single
        .ColumnHeadersBorderStyle = _
            DataGridViewHeaderBorderStyle.Single
    End With

End Sub
private void SetBorderAndGridlineStyles()
{
    this.dataGridView1.GridColor = Color.BlueViolet;
    this.dataGridView1.BorderStyle = BorderStyle.Fixed3D;
    this.dataGridView1.CellBorderStyle =
        DataGridViewCellBorderStyle.None;
    this.dataGridView1.RowHeadersBorderStyle =
        DataGridViewHeaderBorderStyle.Single;
    this.dataGridView1.ColumnHeadersBorderStyle =
        DataGridViewHeaderBorderStyle.Single;
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「DataGridViewCellBorderStyle」の関連用語

DataGridViewCellBorderStyleのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



DataGridViewCellBorderStyleのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS