Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Data.OleDb
Imports System.Windows
Imports DevExpress.Xpf.PivotGrid
Imports HowToBindToMDB.NwindDataSetTableAdapters
Imports System.IO
Imports DevExpress.Xpf.Core
Namespace HowToBindToMDB
''' <summary>
''' Interaction logic for MainWindow.xaml
''' </summary>
Partial Public Class MainWindow
Inherits Window
Private salesPersonDataTable As New NwindDataSet.SalesPersonDataTable()
Private salesPersonDataAdapter As New SalesPersonTableAdapter()
Public Sub New()
InitializeComponent()
pivotGridControl1.DataSource = salesPersonDataTable
End Sub
Private Sub Window_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
salesPersonDataAdapter.Fill(salesPersonDataTable)
End Sub
Private Sub button1_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
pivotGridControl1.SavePivotGridToFile("pivot.dat", True)
pivotGridControl1.DataSource = Nothing
pivotGridControl1.Fields.Clear()
End Sub
Private Sub button2_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
If (Not File.Exists("pivot.dat")) Then
DXMessageBox.Show("You should save the PivotGrid into a file first")
Return
End If
pivotGridControl1.RestorePivotGridFromFile("pivot.dat")
End Sub
End Class
End Namespace
<Window x:Class="HowToBindToMDB.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dxpg="http://schemas.devexpress.com/winfx/2008/xaml/pivotgrid"
Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<dxpg:PivotGridControl dxpg:PivotSerializationOptions.RemoveOldFields="False"
HorizontalAlignment="Left" Name="pivotGridControl1"
VerticalAlignment="Top" Margin="0,0,0,8">
<dxpg:PivotGridControl.Fields>
<dxpg:PivotGridField Name="fieldCountry" FieldName="Country" Area="RowArea" />
<dxpg:PivotGridField Name="fieldCustomer" FieldName="Sales Person" Area="RowArea"
Caption="Customer" />
<dxpg:PivotGridField Name="fieldYear" FieldName="OrderDate" Area="ColumnArea"
Caption="Year" GroupInterval="DateYear" />
<dxpg:PivotGridField Name="fieldCategoryName" FieldName="CategoryName"
Area="ColumnArea" Caption="Product Category" />
<dxpg:PivotGridField Name="fieldProductName" FieldName="ProductName"
Area="FilterArea" Caption="Product Name" />
<dxpg:PivotGridField Name="fieldExtendedPrice" FieldName="Extended Price"
Area="DataArea" CellFormat="c0" />
</dxpg:PivotGridControl.Fields>
</dxpg:PivotGridControl>
<StackPanel Orientation="Horizontal" Grid.Row="1">
<Button Content="Save and unbind" Height="23" Name="button1"
Grid.Row="1" Click="button1_Click"
Margin="0,0,8,0" Padding="8,0,8,0" />
<Button Content="Restore" Height="23" Name="button2"
Grid.Row="1" Grid.Column="1"
Click="button2_Click"
Padding="8,0,8,0" />
</StackPanel>
</Grid>
</Window>
using System.Data;
using System.Data.OleDb;
using System.Windows;
using DevExpress.Xpf.PivotGrid;
using HowToBindToMDB.NwindDataSetTableAdapters;
using System.IO;
using DevExpress.Xpf.Core;
namespace HowToBindToMDB {
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window {
NwindDataSet.SalesPersonDataTable salesPersonDataTable = new NwindDataSet.SalesPersonDataTable();
SalesPersonTableAdapter salesPersonDataAdapter = new SalesPersonTableAdapter();
public MainWindow() {
InitializeComponent();
pivotGridControl1.DataSource = salesPersonDataTable;
}
private void Window_Loaded(object sender, RoutedEventArgs e) {
salesPersonDataAdapter.Fill(salesPersonDataTable);
}
private void button1_Click(object sender, RoutedEventArgs e) {
pivotGridControl1.SavePivotGridToFile("pivot.dat", true);
pivotGridControl1.DataSource = null;
pivotGridControl1.Fields.Clear();
}
private void button2_Click(object sender, RoutedEventArgs e) {
if(!File.Exists("pivot.dat")) {
DXMessageBox.Show("You should save the PivotGrid into a file first");
return;
}
pivotGridControl1.RestorePivotGridFromFile("pivot.dat");
}
}
}