V4 V5

GridViewport holds the view state: which part of the sheet is shown and how. The model (Worksheet) holds no display state at all.

A viewport with a scroll position and an active cell

The namespace is unvell.ReoGrid.Core.Rendering.

Full virtualization

Drawing happens only for cells in the visible range. Even on a 1,048,576-row sheet, a frame deals with the few dozen rows that are on screen.

work ∝ visible cells     (independent of the sheet's dimensions)

That holds for hit-testing, cell-type drawing and conditional-format evaluation too, not just painting.

Creating one and rendering

using unvell.ReoGrid.Core;
using unvell.ReoGrid.Core.Rendering;

var viewport = new GridViewport(ws);
var graphics = new TraceGraphics();

viewport.Render(graphics, viewWidth: 800, viewHeight: 600);

With a control you never need to create one — the viewport is managed internally. Do this when you want to render to your own target (A Custom Drawing Layer).

Settings

var viewport = new GridViewport(ws)
{
	ShowGridLines = true,
	ShowHeaders = true,
	ShowImages = true,
	ShowSelection = false,      // hide the selection frame when exporting
	ShowFillHandle = false,
	Zoom = 1.0,
};

viewport.ScrollX = 0;
viewport.ScrollY = 0;
viewport.FrozenRows = 1;

var (firstRow, lastRow) = viewport.VisibleRows(600);
var (firstCol, lastCol) = viewport.VisibleColumns(800);

The main properties

PropertyWhat it is
ScrollX / ScrollYScroll position in logical pixels
ZoomZoom factor (0.1 to 4.0)
FrozenRows / FrozenColsFreeze panes
ActiveCell / SelectionThe active cell and the selection
ShowGridLines / ShowHeaders / ShowSelection / ShowImages / ShowOutlines / ShowFillHandleWhat to draw
RowHeaderWidth / ColumnHeaderHeightHeader sizes
ThemeThe color palette
ContentWidth / ContentHeightThe whole sheet’s drawn size

Finding the visible range

VisibleRows(viewHeight) and VisibleColumns(viewWidth) return the visible indices for the current scroll position and zoom. Hidden rows and columns are excluded.

Coordinate system

Everything is in logical pixels (at 96 DPI).

LayerConversion
WinFormsapplies RenderScale = DpiScale × Zoom to reach physical pixels
WPF / AvaloniaDIP already is the logical pixel; no conversion
PDFconverted to points

Highlight frames

You can draw a frame around any range — this is what formula reference highlighting uses.

viewport.SetHighlights(frames);   // an array of HighlightFrame(Range, Color)
viewport.ClearHighlights();

Kept apart from the model

Viewport state is not saved. Scroll position, selection and display toggles are run-time state and are written to neither reogrid-json nor XLSX.

Frozen panes, the zoom factor and the gridline/header toggles are the exception: they are per-sheet settings (Worksheet.View) and are saved to both reogrid-json and XLSX (<sheetViews>). A control adopts them through GridViewport.BindToSheetView() and writes changes back (Freeze Panes).

Was this article helpful?