DataGridViewColumn.Frozen DataGridViewColumn.Frozen DataGridViewColumn.Frozen DataGridViewColumn.Frozen Property

定义

获取或设置一个值,指示当用户水平滚动 DataGridView 控件时,列是否移动。Gets or sets a value indicating whether a column will move when a user scrolls the DataGridView control horizontally.

public:
 virtual property bool Frozen { bool get(); void set(bool value); };
public override bool Frozen { get; set; }
member this.Frozen : bool with get, set
Public Overrides Property Frozen As Boolean

属性值

若要冻结该列,则为 true;否则为 falsetrue to freeze the column; otherwise, false.

示例

下面的代码示例演示如何使用DataGridViewBand.Frozen属性,该属性与DataGridViewColumn类的Frozen属性几乎完全相同。The following code example demonstrates how to use the DataGridViewBand.Frozen property, which is nearly identical to the Frozen property of the DataGridViewColumn class. 此代码示例是为DataGridViewBand类提供的更大示例的一部分。This code example is part of a larger example provided for the DataGridViewBand class.

// Freeze the first row.
void Button4_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
   FreezeBand( dataGridView->Rows[ 0 ] );
}

void Button5_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
   FreezeBand( dataGridView->Columns[ 1 ] );
}

void FreezeBand( DataGridViewBand^ band )
{
   band->Frozen = true;
   DataGridViewCellStyle^ style = gcnew DataGridViewCellStyle;
   style->BackColor = Color::WhiteSmoke;
   band->DefaultCellStyle = style;
}


// Freeze the first row.
private void Button4_Click(object sender, System.EventArgs e)
{

    FreezeBand(dataGridView.Rows[0]);
}

private void Button5_Click(object sender, System.EventArgs e)
{

    FreezeBand(dataGridView.Columns[1]);
}

private static void FreezeBand(DataGridViewBand band)
{
    band.Frozen = true;
    DataGridViewCellStyle style = new DataGridViewCellStyle();
    style.BackColor = Color.WhiteSmoke;
    band.DefaultCellStyle = style;
}
' Freeze the first row.
Private Sub Button4_Click(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles Button4.Click

    FreezeBand(dataGridView.Rows(0))
End Sub

Private Sub FreezeColumn(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles Button5.Click

    FreezeBand(dataGridView.Columns(1))
End Sub

Private Shared Sub FreezeBand(ByVal band As DataGridViewBand)

    band.Frozen = True
    Dim style As DataGridViewCellStyle = New DataGridViewCellStyle()
    style.BackColor = Color.WhiteSmoke
    band.DefaultCellStyle = style

End Sub

注解

当某个列处于冻结状态时,它左侧的所有列(或从右到左的语言的右边)也将被冻结。When a column is frozen, all the columns to its left (or to its right in right-to-left languages) are frozen as well. 冻结和未冻结的列构成了两个组。The frozen and unfrozen columns form two groups. 如果通过将AllowUserToOrderColumns属性设置为来启用列重true定位,则用户不能将列从一个组拖动到另一个组。If column repositioning is enabled by setting the AllowUserToOrderColumns property to true, the user cannot drag a column from one group to the other.

适用于

另请参阅