Back to Devexpress

How to: Freeze and Unfreeze Rows and Columns

officefileapi-403951-spreadsheet-document-api-examples-rows-and-columns-how-to-freeze-and-unfreeze-rows-and-columns.md

latest3.3 KB
Original Source

How to: Freeze and Unfreeze Rows and Columns

  • May 25, 2022
  • 2 minutes to read

This topic describes how to keep specific rows and columns visible while you scroll through the worksheet.

Freeze Rows

Call one of the Worksheet.FreezeRows method overloads to freeze a specific number of rows at the top of the worksheet.

The following code snippet freezes the first row:

csharp
using DevExpress.Spreadsheet;
// ...

using (var workbook = new Workbook()) {
    // Access the first worksheet in the workbook.
    var worksheet = workbook.Worksheets[0];

    // Freeze the top row in the worksheet.
    worksheet.FreezeRows(0);
}
vb
Imports DevExpress.Spreadsheet
' ...

Using workbook As New Workbook()
    ' Access the first worksheet in the workbook.
    Dim worksheet As Worksheet = workbook.Worksheets(0)

    ' Freeze the top row in the worksheet.
    worksheet.FreezeRows(0)
End Using

Freeze Columns

Call one of the Worksheet.FreezeColumns method overloads to freeze a specific number of columns on the left side of the worksheet.

The following code snippet freezes the first column:

csharp
using DevExpress.Spreadsheet;
// ...

using (var workbook = new Workbook()) {
    // Access the first worksheet in the workbook.
    var worksheet = workbook.Worksheets[0];

    // Freeze the first column in the worksheet.
    worksheet.FreezeColumns(0);
}
vb
Imports DevExpress.Spreadsheet
' ...

Using workbook As New Workbook()
    ' Access the first worksheet in the workbook.
    Dim worksheet As Worksheet = workbook.Worksheets(0)

    ' Freeze the first column in the worksheet.
    worksheet.FreezeColumns(0)
End Using

Freeze Panes

Call one of the Worksheet.FreezePanes method overloads to freeze a specific number of topmost rows and leftmost columns in the worksheet.

The following code snippet freezes a pane that contains the first row and the first column:

csharp
using DevExpress.Spreadsheet;
// ...

using (var workbook = new Workbook()) {
    // Access the first worksheet in the workbook.
    var worksheet = workbook.Worksheets[0];

    // Freeze the first row and the first column in the worksheet.
    worksheet.FreezePanes(0,0);
}
vb
Imports DevExpress.Spreadsheet
' ...

Using workbook As New Workbook()
    ' Access the first worksheet in the workbook.
    Dim worksheet As Worksheet = workbook.Worksheets(0)

    ' Freeze the first row and the first column in the worksheet.
    worksheet.FreezePanes(0,0)
End Using

Unfreeze Panes

Call the Worksheet.UnfreezePanes method to unlock the frozen rows and columns in the worksheet.

csharp
worksheet.UnfreezePanes();
vb
worksheet.UnfreezePanes()