Imports System.Net
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Documents
Imports System.Windows.Input
Imports System.Windows.Media
Imports System.Windows.Media.Animation
Imports System.Windows.Shapes
Imports C1.Silverlight.Pdf
Imports C1.Silverlight.FlexGrid

Namespace MultiGridPdf
	Partial Public Class MainPage
		Inherits UserControl
		Public Sub New()
			InitializeComponent()

			' load data into first grid
			_flex1.ItemsSource = Product.GetProducts(120)
			_flex1.CollectionView.Filter = AddressOf FilterComputers

			' load data into second grid
			_flex2.ItemsSource = Product.GetProducts(120)
			_flex2.CollectionView.Filter = AddressOf FilterStoves

			' load data into third grid
			_flex3.ItemsSource = Product.GetProducts(120)
			_flex3.CollectionView.Filter = AddressOf FilterWashers

			' load data into last grid
			_flex4.ItemsSource = Product.GetProducts(120)
			_flex4.CollectionView.Filter = AddressOf FilterComputers
		End Sub
		Private Function FilterComputers(ByVal item As Object) As Boolean
			Dim p = TryCast(item, Product)
			Return p.Line = "Computers"
		End Function
		Private Function FilterStoves(ByVal item As Object) As Boolean
			Dim p = TryCast(item, Product)
			Return p.Line = "Stoves"
		End Function
		Private Function FilterWashers(ByVal item As Object) As Boolean
			Dim p = TryCast(item, Product)
			Return p.Line = "Washers"
		End Function

		' generate a PDF document with both grids
		Private Sub Button_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
			Dim dlg = New SaveFileDialog()
			dlg.Filter = "PDF files (*.pdf)|*.pdf"
			If dlg.ShowDialog().Value Then
				' create pdf document
				Dim pdf = New C1PdfDocument()

				' render all grids into pdf document
				Dim options = New PdfExportOptions()
				options.ScaleMode = ScaleMode.ActualSize
				GridExport.RenderGrid(pdf, _flex1, options)
				pdf.NewPage()
				GridExport.RenderGrid(pdf, _flex2, options)
				pdf.NewPage()
				GridExport.RenderGrid(pdf, _flex3, options)
				pdf.NewPage()
				GridExport.RenderGrid(pdf, _flex4, options)

				' save document
				Using stream = dlg.OpenFile()
					pdf.Save(stream)
				End Using
			End If
		End Sub
	End Class
End Namespace
