# Form1.cs
public Form1()
{
InitializeComponent();
this.InitializePivotGrid();
}
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.ShowGroupBar = true;
this.pivotGridControl1.TableControl.FilterArea.QueryCellInfo += FilterArea_QueryCellInfo;
}
private void FilterArea_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
{
if (e.RowIndex == 2 && e.ColIndex == 1)
{
e.Style.Text = "Drop fields here";
e.Style.TextColor = System.Drawing.Color.White;
}
} |