|
Form1.cs
/// <summary>
/// Grid Settings for better look and feel
/// </summary>
private void InitializePivotGrid()
{
// Adding ItemSource to the Control
this.pivotGridControl1.ItemSource = ProductSalesData.GetSalesData();
// Adding PivotRows to the Control
this.pivotGridControl1.PivotRows.Add(new PivotItem { FieldMappingName = "Product", TotalHeader = "Total" });
this.pivotGridControl1.PivotRows.Add(new PivotItem { FieldMappingName = "Date", TotalHeader = "Total" });
// Adding PivotColumns to the Control
this.pivotGridControl1.PivotColumns.Add(new PivotItem { FieldMappingName = "Country", TotalHeader = "Total" });
this.pivotGridControl1.PivotColumns.Add(new PivotItem { FieldMappingName = "State", TotalHeader = "Total" });
// Adding PivotCalculations to the Control
this.pivotGridControl1.PivotCalculations.Add(new PivotComputationInfo { FieldName = "Amount", Format = "$ #,##0.00", SummaryType = SummaryType.DoubleTotalSum });
this.pivotGridControl1.PivotCalculations.Add(new PivotComputationInfo { FieldName = "Quantity", Format = "#,##0" });
this.pivotGridControl1.TableControl.SelectionChanged += TableControl_SelectionChanged;
//tab key navigation set as false to move the next control
this.pivotGridControl1.TableControl.WantTabKey = false;
this.pivotGridControl1.TableModel.Options.AllowSelection = GridSelectionFlags.Any;
}
/// <summary>
/// Occurs when cell selection gets changed.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="Syncfusion.Windows.Forms.PivotAnalysis.PivotGridSelectionChangedEventArgs"/> that contains the event data.</param>
private void TableControl_SelectionChanged(object sender, PivotGridSelectionChangedEventArgs e)
{
if (listBox1.Items.Count > 0)
listBox1.Items.Clear();
if (e.SelectedItems != null)
{
for (int i = 0; i < e.SelectedItems.Count; i++)
{
listBox1.Items.Add(e.SelectedItems[i].ToString());
}
}
} |