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.

適用於

另請參閱