Loading...
Loading...
Complete guide for implementing the Syncfusion WPF GridControl — an Excel-like, cell-based virtual grid for Windows Presentation Foundation applications. Use this when working with WPF GridControl or Syncfusion grid components, including cell types, virtual grids, formula cells, clipboard operations, and Excel import/export. Covers QueryCellInfo events, GridStyleInfo, GridModel, row/column management, and appearance customization for desktop applications.
npx skill4agent add syncfusion/wpf-ui-components-skills syncfusion-wpf-excel-like-gridQueryCellInfoQueryCellInfoRowCountColumnCountQueryCellInfoStyle.CellTypeChoiceListItemsSourceGridStyleInfoBaseStylesMapFormatProviderSetHiddenCopyPasteOptionTextDataExchangeIGridCopyPasteCommandStackBeginTransCommitTransRollbackAllowDragColumnsAllowDragDropDataObjectConsumerOptionsHiddenBorderBrushSetHiddenFormulaCellSyncfusion.XlsIOSyncfusion.GridConverter.WpfAllowSelectionQueryCellInfoPrepareRenderCellCommitCellInfoCurrentCellActivatedRowsInsertedColumnsMovedResizingRowsGridRangeInfoSelectedRangesQueryCellInfoCoveredCells 1. Add assemblies:
Syncfusion.Grid.Wpf
Syncfusion.GridCommon.Wpf,
Syncfusion.Linq.Base,
Syncfusion.Shared.Wpf
// 2. XAML — place GridControl inside a ScrollViewer
<ScrollViewer>
<syncfusion:GridControl x:Name="gridControl" />
</ScrollViewer>
// 3. Code-behind: set size and populate
gridControl.Model.RowCount = 100;
gridControl.Model.ColumnCount = 10;
// Option A — direct assignment
for (int i = 0; i < 100; i++)
for (int j = 0; j < 10; j++)
gridControl.Model[i, j].CellValue = $"{i}/{j}";
// Option B — virtual mode (preferred for large data)
gridControl.QueryCellInfo += (s, e) =>
{
if (e.Cell.RowIndex > 0 && e.Cell.ColumnIndex > 0)
e.Style.CellValue = $"{e.Cell.RowIndex}/{e.Cell.ColumnIndex}";
};// Set an entire column to CheckBox
for (int i = 1; i <= gridControl.Model.RowCount; i++)
gridControl.Model[i, 3].CellType = "CheckBox";gridControl.PrepareRenderCell += (s, e) =>
{
if (e.Cell.RowIndex > 0 && e.Cell.RowIndex % 2 == 0)
e.Style.Background = Brushes.LightSkyBlue;
};gridControl.Model.FrozenRows = 1;
gridControl.Model.HeaderRows = 1;
gridControl.BaseStylesMap["Standard"].StyleInfo.CellType = "FormulaCell";gridControl.Model.ExportToExcel(@"Output.xlsx", ExcelVersion.Excel2007);| Property | Purpose |
|---|---|
| Sets built-in or custom cell type string |
| Data value stored in the cell |
| Cell background brush |
| Cell text color |
| Cell font size |
| Individual border pens (Top/Bottom/Left/Right) |
| Format string (e.g., |
| Row height in device-independent units |
| Column width |
| Number of rows frozen at top |
| Number of columns frozen at left |
undefined