[]
        
(Showing Draft Content)

Scroll

Spread for WPF provides various options for navigating large worksheets, including pixel scrolling, freezing or splitting panes while scrolling, and programmatic scrolling through code.

Below are detailed explanations for each option to help you navigate worksheets efficiently.

Scroll By Pixels

Spread for WPF provides comprehensive support for Excel-like precision scrolling, ensuring a smooth and seamless scrolling experience while providing enhanced control over your worksheets. You can scroll horizontally or vertically by a specified number of pixels, allowing accurate movement across worksheet cells. By default, the worksheet scrolls only by rows or columns.

Pixel scrolling can be especially useful in scenarios such as:

  • When cells in the spreadsheet are very tall (containing multi-line text) or wide (due to increased column width).

  • When positioning a shape or picture within a cell.

  • When entering a large amount of data into a single cell, such as in entry forms, survey forms, or records.

  • When navigating to a specific area or range of cells that contains desired data within the worksheet.

Pixel scrolling is enabled for both horizontal and vertical scrolling, allowing precise control in both directions. Here are the ways you can use pixel scrolling:

  • Use the arrow buttons on the horizontal and vertical scrollbars to scroll.

  • Move the mouse wheel to scroll smoothly across rows or columns.

  • Drag the thumb button (scroll box) on the horizontal and vertical scrollbars to scroll.

Scroll modes determine how horizontal and vertical scroll bars work in a worksheet. To specify the scroll mode and change the default behavior of scroll bars, use the HorizontalScrollMode and VerticalScrollMode enumerations. The table below lists various scroll mode options available for both the enumerations.

Values

Description

Row/Column

Scrolls by rows and columns.

This is the default value.

Pixel

Scrolls pixel by pixel in both directions.

PixelAndRow/PixelAndColumn

Scrolls by pixels with the mouse, then switches to row and column-based movement once the mouse button is released.

The GIF below illustrates pixel scrolling in action, demonstrating how it enables more controlled navigation within a worksheet.

Spread for WPF uses HorizontalScrollMode and VerticalScrollMode set to Pixel so users can move smoothly through worksheet cells in both directions.

Refer to the following example code to enable pixel scrolling in the worksheet.

C#

// Scroll columns and rows by pixels.
spreadSheet1.HorizontalScrollMode = HorizontalScrollMode.Pixel;
spreadSheet1.VerticalScrollMode = VerticalScrollMode.Pixel;
spreadSheet1.HorizontalScrollBarSmallChange = 5;
spreadSheet1.VerticalScrollBarSmallChange = 5;

VB

' Scroll columns and rows by pixels.
spreadSheet1.HorizontalScrollMode = HorizontalScrollMode.Pixel
spreadSheet1.VerticalScrollMode = VerticalScrollMode.Pixel
spreadSheet1.HorizontalScrollBarSmallChange = 5
spreadSheet1.VerticalScrollBarSmallChange = 5

Scroll to Specific Cell

You can easily scroll to the specific position within the worksheet by using the ScrollToCell method of the GcSpreadSheet class.

The following GIF illustrates how to scroll directly to a specified position in the worksheet through code.

Spread for WPF ScrollToCell moves the worksheet directly to row 24, placing the requested cell at the top-left viewport position.

Refer to the following example code to scroll directly to row index 24.

C#

// Scroll to cell with row index 24.
spreadSheet1.ScrollToCell(0, 0, 24, 0, ScrollMode.TopLeft);

VB

' Scroll to cell with row index 24.
spreadSheet1.ScrollToCell(0, 0, 24, 0, ScrollMode.TopLeft)

Scroll Horizontally and Vertically

Spread for WPF allows you to scroll worksheet panes horizontally and vertically. You can use the Panes property of the IWorksheet interface to access all panes in a worksheet, and then use the IPane interface to activate a pane, get its current scroll position, or scroll the pane horizontally and vertically.

The following table lists the main APIs for scrolling worksheet panes.

API

Description

IWorksheet.Panes

Gets all panes of the worksheet.

IPanes.Count

Gets the total number of panes in the worksheet.

IPane.Index

Gets the index number of the pane within the worksheet.

IPane.ScrollColumn

Gets the number of the leftmost column in the pane.

IPane.ScrollRow

Gets the number of the row that appears at the top of the pane.

IPane.Activate

Activates the pane so that subsequent operations apply to the intended pane in worksheets that contain multiple panes.

IPane.ScrollIntoView

Scrolls the document so that the specified rectangular area is displayed in the viewport.

IPane.SmallScroll

Scrolls the pane by columns or rows. Use a positive horizontal value to scroll right, a negative horizontal value to scroll left, a positive vertical value to scroll down, and a negative vertical value to scroll up.

IPane.LargeScroll

Scrolls the pane by pages. Use a positive horizontal value to scroll right, a negative horizontal value to scroll left, a positive vertical value to scroll down, and a negative vertical value to scroll up.

Scroll by Rows or Columns

Use the SmallScroll method to scroll a pane by a specified number of columns and rows.

Spread for WPF SmallScroll moves the first worksheet pane three columns right and two rows down for controlled pane navigation.

Refer to the following example code to scroll the first pane three columns to the right and two rows down.

C#

// Scroll the first pane by columns and rows.
var worksheet = spreadSheet1.Workbook.ActiveSheet;
var pane = worksheet.Panes[0];
pane.SmallScroll(3, 2);

VB

' Scroll the first pane by columns and rows.
Dim worksheet = spreadSheet1.Workbook.ActiveSheet
Dim pane = worksheet.Panes(0)
pane.SmallScroll(3, 2)

Scroll by Pages

Use the LargeScroll method to move through the worksheet one or more pages at a time. This is helpful when navigating large datasets more quickly.

Spread for WPF LargeScroll moves the first worksheet pane one page to the right for faster navigation through a large dataset.

Refer to the following example code to scroll the first pane one page to the right.

C#

// Scroll the first pane by one page horizontally.
var worksheet = spreadSheet1.Workbook.ActiveSheet;
var pane = worksheet.Panes[0];
pane.LargeScroll(1, 0);

VB

' Scroll the first pane by one page horizontally.
Dim worksheet = spreadSheet1.Workbook.ActiveSheet
Dim pane = worksheet.Panes(0)
pane.LargeScroll(1, 0)

Scroll a Specific Area into View

Spread for WPF ScrollIntoView shifts the worksheet pane until the specified rectangular area is visible within the viewport.

Use the ScrollIntoView method to scroll the pane so that a specified rectangular area is displayed in the viewport. The position and size of the rectangle are specified in pixels.

Refer to the following example code to scroll the pane so that the specified area becomes visible.

C#

// Scroll the pane so that the specified rectangle is visible.
var worksheet = spreadSheet1.Workbook.ActiveSheet;
var pane = worksheet.Panes[0];
pane.ScrollIntoView(600, 0, 200, 120);

VB

' Scroll the pane so that the specified rectangle is visible.
Dim worksheet = spreadSheet1.Workbook.ActiveSheet
Dim pane = worksheet.Panes(0)
pane.ScrollIntoView(600, 0, 200, 120)

Get the Current Scroll Position

You can use the ScrollColumn and ScrollRow properties to determine the current scroll position of a pane.

Refer to the following example code to get the top row and leftmost column of the first pane.

C#

// Get the current scroll position of the first pane.
var worksheet = spreadSheet1.Workbook.ActiveSheet;
var pane = worksheet.Panes[0];
int leftColumn = pane.ScrollColumn;
int topRow = pane.ScrollRow;

VB

' Get the current scroll position of the first pane.
Dim worksheet = spreadSheet1.Workbook.ActiveSheet
Dim pane = worksheet.Panes(0)
Dim leftColumn As Integer = pane.ScrollColumn
Dim topRow As Integer = pane.ScrollRow

Scroll Horizontally Using Mouse Wheel

Similar to Excel, Spread for WPF also provides a convenient way to navigate horizontally within a worksheet using the mouse wheel and Ctrl+ Shift keys.

  • To scroll Right: Hold the Ctrl + Shift keys and scroll down the mouse wheel.

  • To scroll Left: Hold the Ctrl + Shift keys and scroll up the mouse wheel.

Set Freeze Panes

The Freeze Panes feature allows you to keep a specific section of the worksheet visible while scrolling through the rest of the data. This is particularly useful in large worksheets, as it helps you to maintain visibility of header rows or columns, ensuring you can easily identify data points as you navigate through the information. To freeze panes in the worksheet, you can use the FreezePanes property of the IWorksheetView interface.

The following GIF illustrates how the freezing header rows in a sales report worksheet helps you to track the column names while viewing data further down. It provides a clearer view of the data as you scroll through the worksheet.

Spread for WPF FreezePanes keeps the sales report header row and leading columns visible while users scroll through worksheet data.

The sample code below demonstrates the method for freezing panes in a worksheet.

C#

// Set freeze panes.
spreadSheet1.Workbook.ActiveSheet.View.SplitColumn = 3;
spreadSheet1.Workbook.ActiveSheet.View.SplitRow = 1;
spreadSheet1.Workbook.ActiveSheet.View.FreezePanes = true;

VB

' Set freeze panes.
spreadSheet1.Workbook.ActiveSheet.View.SplitColumn = 3
spreadSheet1.Workbook.ActiveSheet.View.SplitRow = 1
spreadSheet1.Workbook.ActiveSheet.View.FreezePanes = True

Set Split Panes

Split panes allow you to divide a worksheet into separate sections or panes, which can be scrolled independently. This feature makes it easier to work with large datasets. To split panes in a worksheet, you can use the Split property of the IWorkSheetView interface.

The following GIF illustrates how the spliting panes in a large sales report worksheet improves navigation and maintains header visibility while scrolling, enabling a more organized view of the data.

Spread for WPF Split divides the sales report worksheet into independently scrollable panes, preserving access to headers while navigating data.

Refer to the following example code to set splitting panes in a worksheet.

C#

// Set split panes.
spreadSheet1.Workbook.ActiveSheet.View.SplitHorizontal = 450; // Pixels
spreadSheet1.Workbook.ActiveSheet.View.SplitVertical = 430; // Pixels
spreadSheet1.Workbook.ActiveSheet.View.Split = true;

VB

' Set split panes.
spreadSheet1.Workbook.ActiveSheet.View.SplitHorizontal = 450 ' Pixels
spreadSheet1.Workbook.ActiveSheet.View.SplitVertical = 430 ' Pixels
spreadSheet1.Workbook.ActiveSheet.View.Split = True