WPF Support

ReoGrid can work with both Windows Form and WPF. The core of ReoGrid works for both platform, there are independent view modules for rendering and handling user interface on each platform. The APIs of control that faced to user code are almost the same. User code that uses ReoGrid graphics interface for rendering custom cell or handling user event in cell can work on different platform.

reogrid_087_construction

Same one template file such as Excel or RGF that can display on Windows Form platform as well as WPF platform. Below are the results from different platforms that uses same template (order_sample.rgf).

155

As the result ReoGrid tries to keep almost the same appearance for different platforms.

Add spreadsheet control in XAML

Add ReoGrid DLL reference for target project, edit the XAML file of main window as below:

File MainWindow.xaml:

<Window
  xmlns="/schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="/schemas.microsoft.com/winfx/2006/xaml"
  xmlns:rg="clr-namespace:unvell.ReoGrid;assembly=unvell.ReoGrid"
  x:Class="WPFDemo.MainWindow" Title="MainWindow" Height="640" Width="800">
  <Grid>

    <rg:ReoGridControl x:Name="grid" >
    </rg:ReoGridControl>

  </Grid>
</Window>

Make sure the namespace is declared in the attribute list, then define a ReoGridControl tag inside Grid tag, run the application, an empty spreadsheet will be displayed in window like below:

153

In code behind, write code to call APIs of worksheet in order to set same example data and styles:

// get current worksheet instance
var worksheet = grid.CurrentWorksheet;

// get a range reference
var range = worksheet.Ranges["B2:C3"];

// merge the range
range.Merge();

// set range styles
range.Style.BackColor = Graphics.SolidColor.LightYellow;
range.BorderOutside = RangeBorderStyle.BlackSolid;

// set range inner data
range.Data = "Hello World!";

Result:

154

The APIs of WPF edition is totally same as the Windows Form edition, see documentation for more details.

Load a template spreadsheet file

Set attribute LoadFromFile to load a template spreadsheet from file:

<rg:ReoGridControl LoadFromFile="order_sample.rgf" x:Name="grid" >
</rg:ReoGridControl>

By run this sample the template spreadsheet will be displayed. It is possible to fill the data in a specified range by code after loading:

public MainWindow()
{
  InitializeComponent();

  grid.CurrentWorksheet.FileLoaded += CurrentWorksheet_FileLoaded;
}

void CurrentWorksheet_FileLoaded(object sender, unvell.ReoGrid.Events.FileLoadedEventArgs e)
{
  var worksheet = grid.CurrentWorksheet;
  var dataRange = worksheet.Ranges["A21:G35"];
  dataRange.Data = new object[,]
  {
    {"[23423423]", "Product ABC", 15, 150, 2250},
    {"[45645645]", "Product DEF", 1, 75, 75},
    {"[78978978]", "Product GHI", 2, 30, 60},
  };
}

Result:

155

WPF available features

Some features are not supported in WPF edition.
Feature WinForm WPF
Cell Edit Yes Yes
Grid Resize Yes Yes
Cell & Range Style Yes Yes
Border Style Yes Limited
Selection Style Yes Yes
Data Format Yes Yes
Group and Outline Yes Yes
Freeze Yes Yes
Zoom & Scroll Yes Yes
Print & Preview Yes Yes
Formula & Script Yes Yes
Custom Cell/Header Body Yes Yes
Built-in Cell Body Types Yes Limited *1
Control Appearance Yes Yes
Save & Load Yes Yes
Column Filter & Sort Yes API only
Editor & Extension WinForm Controls Yes No

*1 To be available in future versions


Learn more about new features in 0.8.7.