Imports Infragistics.Olap
Imports Infragistics.Olap.FlatData
Imports System.Collections.Generic
Imports System.Windows.Forms
Namespace PivotGrid_FlatDataBinding
Public Partial Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
AddHandler Load, AddressOf SampleForm_Load
End Sub
Private Sub SampleForm_Load(sender As Object, e As EventArgs)
Dim ds As FlatDataSource = InitializePivotData()
' Generate cubes and call "InitializeAsync" method passing the control the data is bound to.
Dim parameters = New CubeGenerationParameters()
ds.GenerateCube(parameters)
ds.InitializeAsync(ultraPivotGrid1)
' Bind the PivotGrid and DataSelector to data.
ultraPivotGrid1.DataSource = ds
olapDataSelector1.DataSource = ds
' Optinally, set compact mode on PivotGrid
ultraPivotGrid1.RowHeaderLayout = Infragistics.Win.UltraWinPivotGrid.RowHeaderLayout.Compact
End Sub
Public Function InitializePivotData() As FlatDataSource
' Initialize the data
Dim data As New SampleFlatData()
Dim itemSource As IEnumerable(Of SportsData) = data.InitSportsData()
' Use "FlatDataSourceInitialSettings" object to initialize Hierarchies and Measures
Dim settings = New FlatDataSourceInitialSettings()
settings.Rows = "[SportsData].[Nation], [SportsData].[Date]"
settings.Columns = "[SportsData].[Sport]"
settings.Measures = "[Measures].[Budget]"
' Create an instance of the FlatDataSource
Dim ds = New FlatDataSource(itemSource, GetType(SportsData), settings)
' Initialize Hierarchy Descriptor
AddHandler ds.InitializeHierarchyDescriptor, AddressOf ds_InitializeHierarchyDescriptor
' Initialize Measure Descriptor
AddHandler ds.InitializeMeasureDescriptor, AddressOf ds_InitializeMeasureDescriptor
' Aggregate measures to produce totals
AddHandler ds.AggregateMeasure, AddressOf ds_AggregateMeasure
Return ds
End Function
Private Sub ds_InitializeHierarchyDescriptor(sender As Object, e As InitializeHierarchyDescriptorEventArgs)
Dim level As LevelDescriptor
If e.HierarchyDescriptor.LevelDescriptors.TryGetItem("all", level) Then
Select Case e.HierarchyDescriptor.PropertyDescriptor.Name
Case "Nation"
level.MemberProvider = Function(item) "All Nations"
Exit Select
Case "City"
level.MemberProvider = Function(item) "All Cities"
Exit Select
Case "Sport"
level.MemberProvider = Function(item) "All Sports"
Exit Select
End Select
End If
End Sub
Private Sub ds_InitializeMeasureDescriptor(sender As Object, e As InitializeMeasureDescriptorEventArgs)
If e.MeasureDescriptor.Name = "Budget" Then
e.MeasureDescriptor.DisplayFormat = "$#"
e.MeasureDescriptor.Aggregation = MeasureAggregation.Average
End If
End Sub
Private Sub ds_AggregateMeasure(sender As Object, e As AggregateMeasureEventArgs)
If e.MeasureDescriptor.Name = "Budget" Then
Dim total As Double = 0F
Dim count As Double = 0F
For Each o As Object In e.Items
Dim item = TryCast(o, SportsData)
If item IsNot Nothing Then
total += item.Budget
End If
count += 1F
Next
e.Value = total / count
e.Handled = True
End If
End Sub
End Class
End Namespace