FlexSheet for WPF | ComponentOne
Working with C1FlexSheet / Sheet Operations / Freezing and Unfreezing Rows and Columns
In This Topic
    Freezing and Unfreezing Rows and Columns
    In This Topic

    You might want to compare data in a worksheet while working on it. However, if the data in the worksheet is in large amount then it becomes difficult to compare. C1FlexSheet allows you to freeze rows and columns that can help you compare different parts of your data easily.

    When you want to compare data in specific rows/columns and want that data fixed at a place in a worksheet while scrolling through the rest of the data in it, you can freeze the rows or columns using Frozen property in C1FlexSheet. Also, when you are done comparing the data, you can unfreeze the rows and columns using Frozen property. You can use the following lines of code to freeze and unfreeze the data in a sheet:

    If flex.Rows.Frozen > 0 OrElse flex.Columns.Frozen > 0 Then
        ' unfreeze
        For i As Int32 = 0 To flex.Rows.Frozen - 1
            flex.Rows(i).Visible = True
        Next
        For i As Int32 = 0 To flex.Columns.Frozen - 1
            flex.Columns(i).Visible = True
        Next
        flex.Rows.Frozen = 0
        flex.Columns.Frozen = 0
    Else
        ' freeze
        Dim vr = flex.ViewRange
        For i As Int32 = 0 To vr.TopRow - 1
            flex.Rows(i).Visible = False
        Next
        For i As Int32 = 0 To vr.LeftColumn - 1
            flex.Columns(i).Visible = False
        Next
        flex.Rows.Frozen = flex.Selection.TopRow
        flex.Columns.Frozen = flex.Selection.LeftColumn
        flex.ScrollIntoView(flex.Rows.Frozen, flex.Columns.Frozen)
    End If
    
    if (flex.Rows.Frozen > 0 || flex.Columns.Frozen > 0)
    {
        // unfreeze
        for (var i = 0; i < flex.Rows.Frozen; i++)
        {
            flex.Rows[i].Visible = true;
        }
        for (var i = 0; i < flex.Columns.Frozen; i++)
        {
            flex.Columns[i].Visible = true;
        }
        flex.Rows.Frozen = 0;
        flex.Columns.Frozen = 0;
    }
    else
    {
        // freeze
        var vr = flex.ViewRange;
        for (var i = 0; i < vr.TopRow; i++)
        {
            flex.Rows[i].Visible = false;
        }
        for (var i = 0; i < vr.LeftColumn; i++)
        {
            flex.Columns[i].Visible = false;
        }
        flex.Rows.Frozen = flex.Selection.TopRow;
        flex.Columns.Frozen = flex.Selection.LeftColumn;
        flex.ScrollIntoView(flex.Rows.Frozen, flex.Columns.Frozen);
    }