DataGridViewCheckBoxColumn.DefaultCellStyle Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets or sets the column's default cell style.
public:
virtual property System::Windows::Forms::DataGridViewCellStyle ^ DefaultCellStyle { System::Windows::Forms::DataGridViewCellStyle ^ get(); void set(System::Windows::Forms::DataGridViewCellStyle ^ value); };
[System.ComponentModel.Browsable(true)]
public override System.Windows.Forms.DataGridViewCellStyle DefaultCellStyle { get; set; }
[<System.ComponentModel.Browsable(true)>]
member this.DefaultCellStyle : System.Windows.Forms.DataGridViewCellStyle with get, set
Public Overrides Property DefaultCellStyle As DataGridViewCellStyle
Property Value
The DataGridViewCellStyle to be applied as the default style.
- Attributes
Examples
The following code example demonstrates the use of this property.
private void ChangeColumnAlignment()
{
songsDataGridView.Columns["Title"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.BottomCenter;
songsDataGridView.Columns["Title"].Name = DataGridViewContentAlignment.BottomCenter.ToString();
songsDataGridView.Columns["Artist"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.BottomLeft;
songsDataGridView.Columns["Artist"].Name = DataGridViewContentAlignment.BottomLeft.ToString();
songsDataGridView.Columns["Album"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.BottomRight;
songsDataGridView.Columns["Album"].Name = DataGridViewContentAlignment.BottomRight.ToString();
songsDataGridView.Columns["Release Date"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
songsDataGridView.Columns["Release Date"].Name = DataGridViewContentAlignment.MiddleCenter.ToString();
songsDataGridView.Columns["Track"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
songsDataGridView.Columns["Track"].Name = DataGridViewContentAlignment.MiddleLeft.ToString();
}
Private Sub ChangeColumnAlignment()
songsDataGridView.Columns("Title").DefaultCellStyle.Alignment = DataGridViewContentAlignment.BottomCenter
songsDataGridView.Columns("Title").Name = DataGridViewContentAlignment.BottomCenter.ToString()
songsDataGridView.Columns("Artist").DefaultCellStyle.Alignment = DataGridViewContentAlignment.BottomLeft
songsDataGridView.Columns("Artist").Name = DataGridViewContentAlignment.BottomLeft.ToString()
songsDataGridView.Columns("Album").DefaultCellStyle.Alignment = DataGridViewContentAlignment.BottomRight
songsDataGridView.Columns("Album").Name = DataGridViewContentAlignment.BottomRight.ToString()
songsDataGridView.Columns("Release Date").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
songsDataGridView.Columns("Release Date").Name = DataGridViewContentAlignment.MiddleCenter.ToString()
songsDataGridView.Columns("Track").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft
songsDataGridView.Columns("Track").Name = DataGridViewContentAlignment.MiddleLeft.ToString()
End Sub
Remarks
The default DataGridViewCellStyle returned by this property has the following initial property values:
DataGridViewCellStyle property |
Default value |
---|---|
Alignment | DataGridViewContentAlignment.MiddleCenter |
NullValue | CheckState.Indeterminate if the initial ThreeState property value is true ; otherwise, false . |
These values override the value specified in the DefaultCellStyle property of the DataGridView control, but may be overridden by other cell style properties. For more information, see Cell Styles in the Windows Forms DataGridView Control.
If the NullValue property of the object returned by the DefaultCellStyle property has a value of false
, changing the ThreeState property value to true
automatically sets NullValue to Indeterminate. If NullValue has a value of Indeterminate, changing the ThreeState property value to false
automatically sets NullValue to false
.
Applies to
See also
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈