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

プロパティ値

Boolean

列を固定する場合は true。それ以外の場合は false

次のコード例は、クラスの DataGridViewBand.Frozen プロパティとほぼ同じプロパティを Frozen 使用する方法を DataGridViewColumn 示しています。 このコード例は、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

注釈

列が固定されると、左 (または右から左の言語では右) のすべての列も固定されます。 固定列と固定解除列は、2 つのグループを形成します。 プロパティtrueを設定して列の位置をAllowUserToOrderColumns変更できる場合、ユーザーは列をグループ間でドラッグできません。

適用対象

こちらもご覧ください