DataGridViewColumn.Frozen 属性

定义

获取或设置一个值,指示当用户水平滚动 DataGridView 控件时,列是否移动。

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;否则为 false

示例

下面的代码示例演示如何使用 DataGridViewBand.Frozen 属性,该属性与 类的 DataGridViewColumn 属性几乎完全相同Frozen。 此代码示例是为 DataGridViewBand 类提供的一个更大示例的一部分。

// 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

注解

冻结列时,其左侧 (或右侧的所有列(以从右到左的语言) )也会被冻结。 冻结列和未冻结列构成两个组。 如果通过将 属性设置为 AllowUserToOrderColumnstrue来启用列重新定位,则用户无法将列从一个组拖动到另一组。

适用于

另请参阅