DataGridView.CellBorderStyle 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得 DataGridView 的儲存格框線樣式。
public:
property System::Windows::Forms::DataGridViewCellBorderStyle CellBorderStyle { System::Windows::Forms::DataGridViewCellBorderStyle get(); void set(System::Windows::Forms::DataGridViewCellBorderStyle value); };
[System.ComponentModel.Browsable(true)]
public System.Windows.Forms.DataGridViewCellBorderStyle CellBorderStyle { get; set; }
[<System.ComponentModel.Browsable(true)>]
member this.CellBorderStyle : System.Windows.Forms.DataGridViewCellBorderStyle with get, set
Public Property CellBorderStyle As DataGridViewCellBorderStyle
屬性值
DataGridViewCellBorderStyle,表示包含在 DataGridView 中之儲存格的框線樣式。
- 屬性
例外狀況
設定這個屬性時所指定的值不是有效的 DataGridViewCellBorderStyle 值。
設定這個屬性時所指定的值是 Custom。
範例
下列程式碼範例示範如何使用 CellBorderStyle 屬性。 若要執行此範例,請將程式碼貼到包含 DataGridView 具名 dataGridView1
的表單中,然後從表單的建構函式或 Load 事件處理常式呼叫 SetUpDataGridView
方法。 確定所有事件都與其事件處理常式相關聯。
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
備註
CellBorderStyle如果 屬性設定為 、 SingleHorizontal 或 SingleVertical 以外的 Single 任何專案,則 GridColor 屬性必須是系統色彩。
您無法將這個屬性設定為 Custom 值,這是唯讀值,表示儲存格框線樣式已透過 屬性使用 AdvancedCellBorderStyle 自訂。