| Task-Based Help > Creating Custom FlexPivot Application in Code > Adding Predefined Views |
Users can add predefined views to their FlexPivot application by defining the views in an XML file and adding the same as a resource to the Project Designer. The C1FlexPivotPage class includes ReadXml and WriteXml methods to add files as streams. These methods are automatically invoked by the FlexPivotPage control to apply predefined views.
| XML |
Copy Code
|
|---|---|
<FlexPivotViews> <C1FlexPivotPage id="Product vs Country"> <C1FlexPivotEngine> <Fields> <Field name="Address" subtotal="Count" /> <Field name="City" subtotal="Count" /> <Field name="Country" subtotal="Count" /> <Field name="CustomerID" subtotal="Count" /> <Field name="Customers_CompanyName" subtotal="Count" /> <Field name="Discount" subtotal="Sum" format="n0" /> <Field name="ExtendedPrice" subtotal="Sum" format="n0" /> <Field name="Freight" subtotal="Sum" format="n0" /> <Field name="OrderDate" subtotal="Count" format="d" /> <Field name="OrderID" subtotal="Sum" format="n0" /> <Field name="PostalCode" subtotal="Count" /> <Field name="ProductID" subtotal="Sum" format="n0" /> <Field name="ProductName" subtotal="Count" /> <Field name="Quantity" subtotal="Sum" format="n0" /> <Field name="Region" subtotal="Count" /> <Field name="RequiredDate" subtotal="Count" format="d" /> <Field name="Salesperson" subtotal="Count" /> <Field name="ShipAddress" subtotal="Count" /> <Field name="ShipCity" subtotal="Count" /> <Field name="ShipCountry" subtotal="Count" /> <Field name="ShipName" subtotal="Count" /> <Field name="ShippedDate" subtotal="Count" format="d" /> <Field name="Shippers_CompanyName" subtotal="Count" /> <Field name="ShipPostalCode" subtotal="Count" /> <Field name="ShipRegion" subtotal="Count" /> <Field name="UnitPrice" subtotal="Sum" format="n0" /> </Fields> <RowFields> <Field name="ProductName" /> </RowFields> <ColumnFields> <Field name="Country" /> </ColumnFields> <ValueFields> <Field name="ExtendedPrice" /> </ValueFields> </C1FlexPivotEngine> <C1FlexPivotPrintDocument> <Header Text="&[ViewTitle]	&[Date]	Page &[Page]" Separator="True" FontName="Arial" FontSize="9" FontStyle="Regular" /> <Footer Text="" Separator="False" FontName="Arial" FontSize="9" FontStyle="Regular" /> <Grid ShowGrid="True" GridOptions="1" /> <Chart ShowChart="True" ChartFillsPage="True" /> <RawData ShowRawData="False" RawDataOptions="1" /> <PageSettings Landscape="False" Margins="100,100,100,100" /> </C1FlexPivotPrintDocument> <C1FlexPivotChart ChartType="Bar" ColorGeneration="Office" ShowTitle="True" ShowLegend="Automatic" ShowGridLines="True" Stacked="True" /> </C1FlexPivotPage> <C1FlexPivotPage id="SalesPerson vs Country"> <C1FlexPivotEngine> <Fields> <Field name="Address" subtotal="Count" /> <Field name="City" subtotal="Count" /> <Field name="Country" subtotal="Count" /> <Field name="CustomerID" subtotal="Count" /> <Field name="Customers_CompanyName" subtotal="Count" /> <Field name="Discount" subtotal="Sum" format="n0" /> <Field name="ExtendedPrice" subtotal="Sum" format="n0" /> <Field name="Freight" subtotal="Sum" format="n0" /> <Field name="OrderDate" subtotal="Count" format="d" /> <Field name="OrderID" subtotal="Sum" format="n0" /> <Field name="PostalCode" subtotal="Count" /> <Field name="ProductID" subtotal="Sum" format="n0" /> <Field name="ProductName" subtotal="Count" /> <Field name="Quantity" subtotal="Sum" format="n0" /> <Field name="Region" subtotal="Count" /> <Field name="RequiredDate" subtotal="Count" format="d" /> <Field name="Salesperson" subtotal="Count" /> <Field name="ShipAddress" subtotal="Count" /> <Field name="ShipCity" subtotal="Count" /> <Field name="ShipCountry" subtotal="Count" /> <Field name="ShipName" subtotal="Count" /> <Field name="ShippedDate" subtotal="Count" format="d" /> <Field name="Shippers_CompanyName" subtotal="Count" /> <Field name="ShipPostalCode" subtotal="Count" /> <Field name="ShipRegion" subtotal="Count" /> <Field name="UnitPrice" subtotal="Sum" format="n0" /> </Fields> <RowFields> <Field name="Country" /> </RowFields> <ColumnFields> <Field name="Salesperson" /> </ColumnFields> <ValueFields> <Field name="ExtendedPrice" /> </ValueFields> </C1FlexPivotEngine> <C1FlexPivotPrintDocument> <Header Text="&[ViewTitle]	&[Date]	Page &[Page]" Separator="True" FontName="Arial" FontSize="9" FontStyle="Regular" /> <Footer Text="" Separator="False" FontName="Arial" FontSize="9" FontStyle="Regular" /> <Grid ShowGrid="True" GridOptions="1" /> <Chart ShowChart="True" ChartFillsPage="True" /> <RawData ShowRawData="False" RawDataOptions="1" /> <PageSettings Landscape="False" Margins="100,100,100,100" /> </C1FlexPivotPrintDocument> <C1FlexPivotChart ChartType="Bar" ColorGeneration="Office" ShowTitle="True" ShowLegend="Automatic" ShowGridLines="True" Stacked="True" /> </C1FlexPivotPage> <C1FlexPivotPage id="SalesPerson vs Month"> <C1FlexPivotEngine> <Fields> <Field name="Address" subtotal="Count" /> <Field name="City" subtotal="Count" /> <Field name="Country" subtotal="Count" /> <Field name="CustomerID" subtotal="Count" /> <Field name="Customers_CompanyName" subtotal="Count" /> <Field name="Discount" subtotal="Sum" format="n0" /> <Field name="ExtendedPrice" subtotal="Sum" format="n0" /> <Field name="Freight" subtotal="Sum" format="n0" /> <Field name="OrderDate" subtotal="Count" format="MMMM" /> <Field name="OrderID" subtotal="Sum" format="n0" /> <Field name="PostalCode" subtotal="Count" /> <Field name="ProductID" subtotal="Sum" format="n0" /> <Field name="ProductName" subtotal="Count" /> <Field name="Quantity" subtotal="Sum" format="n0" /> <Field name="Region" subtotal="Count" /> <Field name="RequiredDate" subtotal="Count" format="d" /> <Field name="Salesperson" subtotal="Count" /> <Field name="ShipAddress" subtotal="Count" /> <Field name="ShipCity" subtotal="Count" /> <Field name="ShipCountry" subtotal="Count" /> <Field name="ShipName" subtotal="Count" /> <Field name="ShippedDate" subtotal="Count" format="d" /> <Field name="Shippers_CompanyName" subtotal="Count" /> <Field name="ShipPostalCode" subtotal="Count" /> <Field name="ShipRegion" subtotal="Count" /> <Field name="UnitPrice" subtotal="Sum" format="n0" /> </Fields> <RowFields> <Field name="Salesperson" /> </RowFields> <ColumnFields> <Field name="OrderDate" /> </ColumnFields> <ValueFields> <Field name="ExtendedPrice" /> </ValueFields> </C1FlexPivotEngine> <C1FlexPivotPrintDocument> <Header Text="&[ViewTitle]	&[Date]	Page &[Page]" Separator="True" FontName="Arial" FontSize="9" FontStyle="Regular" /> <Footer Text="" Separator="False" FontName="Arial" FontSize="9" FontStyle="Regular" /> <Grid ShowGrid="True" GridOptions="1" /> <Chart ShowChart="True" ChartFillsPage="True" /> <RawData ShowRawData="False" RawDataOptions="1" /> <PageSettings Landscape="False" Margins="100,100,100,100" /> </C1FlexPivotPrintDocument> <C1FlexPivotChart ChartType="Bar" ColorGeneration="Office" ShowTitle="True" ShowLegend="Automatic" ShowGridLines="True" Stacked="True" /> </C1FlexPivotPage> <C1FlexPivotPage id="SalesPerson vs Weekday"> <C1FlexPivotEngine> <Fields> <Field name="Address" subtotal="Count" /> <Field name="City" subtotal="Count" /> <Field name="Country" subtotal="Count" /> <Field name="CustomerID" subtotal="Count" /> <Field name="Customers_CompanyName" subtotal="Count" /> <Field name="Discount" subtotal="Sum" format="n0" /> <Field name="ExtendedPrice" subtotal="Sum" format="n0" /> <Field name="Freight" subtotal="Sum" format="n0" /> <Field name="OrderDate" subtotal="Count" format="dddd" /> <Field name="OrderID" subtotal="Sum" format="n0" /> <Field name="PostalCode" subtotal="Count" /> <Field name="ProductID" subtotal="Sum" format="n0" /> <Field name="ProductName" subtotal="Count" /> <Field name="Quantity" subtotal="Sum" format="n0" /> <Field name="Region" subtotal="Count" /> <Field name="RequiredDate" subtotal="Count" format="d" /> <Field name="Salesperson" subtotal="Count" /> <Field name="ShipAddress" subtotal="Count" /> <Field name="ShipCity" subtotal="Count" /> <Field name="ShipCountry" subtotal="Count" /> <Field name="ShipName" subtotal="Count" /> <Field name="ShippedDate" subtotal="Count" format="d" /> <Field name="Shippers_CompanyName" subtotal="Count" /> <Field name="ShipPostalCode" subtotal="Count" /> <Field name="ShipRegion" subtotal="Count" /> <Field name="UnitPrice" subtotal="Sum" format="n0" /> </Fields> <RowFields> <Field name="Salesperson" /> </RowFields> <ColumnFields> <Field name="OrderDate" /> </ColumnFields> <ValueFields> <Field name="ExtendedPrice" /> </ValueFields> </C1FlexPivotEngine> <C1FlexPivotPrintDocument> <Header Text="&[ViewTitle]	&[Date]	Page &[Page]" Separator="True" FontName="Arial" FontSize="9" FontStyle="Regular" /> <Footer Text="" Separator="False" FontName="Arial" FontSize="9" FontStyle="Regular" /> <Grid ShowGrid="True" GridOptions="1" /> <Chart ShowChart="True" ChartFillsPage="True" /> <RawData ShowRawData="False" RawDataOptions="1" /> <PageSettings Landscape="False" Margins="100,100,100,100" /> </C1FlexPivotPrintDocument> <C1FlexPivotChart ChartType="Bar" ColorGeneration="Office" ShowTitle="True" ShowLegend="Automatic" ShowGridLines="True" Stacked="True" /> </C1FlexPivotPage> <C1FlexPivotPage id="SalesPerson vs Year"> <C1FlexPivotEngine> <Fields> <Field name="Address" subtotal="Count" /> <Field name="City" subtotal="Count" /> <Field name="Country" subtotal="Count" /> <Field name="CustomerID" subtotal="Count" /> <Field name="Customers_CompanyName" subtotal="Count" /> <Field name="Discount" subtotal="Sum" format="n0" /> <Field name="ExtendedPrice" subtotal="Sum" format="n0" /> <Field name="Freight" subtotal="Sum" format="n0" /> <Field name="OrderDate" subtotal="Count" format="yyyy" /> <Field name="OrderID" subtotal="Sum" format="n0" /> <Field name="PostalCode" subtotal="Count" /> <Field name="ProductID" subtotal="Sum" format="n0" /> <Field name="ProductName" subtotal="Count" /> <Field name="Quantity" subtotal="Sum" format="n0" /> <Field name="Region" subtotal="Count" /> <Field name="RequiredDate" subtotal="Count" format="d" /> <Field name="Salesperson" subtotal="Count" /> <Field name="ShipAddress" subtotal="Count" /> <Field name="ShipCity" subtotal="Count" /> <Field name="ShipCountry" subtotal="Count" /> <Field name="ShipName" subtotal="Count" /> <Field name="ShippedDate" subtotal="Count" format="d" /> <Field name="Shippers_CompanyName" subtotal="Count" /> <Field name="ShipPostalCode" subtotal="Count" /> <Field name="ShipRegion" subtotal="Count" /> <Field name="UnitPrice" subtotal="Sum" format="n0" /> </Fields> <RowFields> <Field name="Salesperson" /> </RowFields> <ColumnFields> <Field name="OrderDate" /> </ColumnFields> <ValueFields> <Field name="ExtendedPrice" /> </ValueFields> </C1FlexPivotEngine> <C1FlexPivotPrintDocument> <Header Text="&[ViewTitle]	&[Date]	Page &[Page]" Separator="True" FontName="Arial" FontSize="9" FontStyle="Regular" /> <Footer Text="" Separator="False" FontName="Arial" FontSize="9" FontStyle="Regular" /> <Grid ShowGrid="True" GridOptions="1" /> <Chart ShowChart="True" ChartFillsPage="True" /> <RawData ShowRawData="False" RawDataOptions="1" /> <PageSettings Landscape="False" Margins="100,100,100,100" /> </C1FlexPivotPrintDocument> <C1FlexPivotChart ChartType="Bar" ColorGeneration="Office" ShowTitle="True" ShowLegend="Automatic" ShowGridLines="True" Stacked="True" /> </C1FlexPivotPage> </FlexPivotViews> |
|
) and Views_small.png (
) in a folder named, for example, Resources.

' build menu with predefined views: Dim doc = New System.Xml.XmlDocument() doc.LoadXml(My.Resources.FlexPivotViews) Dim menuView = New C1.Win.C1Command.C1CommandMenu() menuView.Text = "&View" menuView.Image = My.Resources.Views_small
// build menu with predefined views: var doc = new System.Xml.XmlDocument(); doc.LoadXml(Properties.Resources.FlexPivotViews); var menuView = new C1.Win.C1Command.C1CommandMenu(); menuView.Text = "&View"; menuView.Image = Properties.Resources.Views_small;
For Each nd As System.Xml.XmlNode In doc.SelectNodes("FlexPivotViews/C1FlexPivotPage") Dim cmd = New C1.Win.C1Command.C1Command() cmd.Text = nd.Attributes("id").Value cmd.UserData = nd AddHandler cmd.Click, AddressOf menuView_DropDownItemClicked Dim link = New C1.Win.C1Command.C1CommandLink(cmd) menuView.CommandLinks.Add(link) Next nd
foreach (System.Xml.XmlNode nd in doc.SelectNodes("FlexPivotViews/C1FlexPivotPage")) { var cmd = new C1.Win.C1Command.C1Command(); cmd.Text = nd.Attributes["id"].Value; cmd.UserData = nd; cmd.Click += menuView_DropDownItemClicked; var link = new C1.Win.C1Command.C1CommandLink(cmd); menuView.CommandLinks.Add(link); }
Private Sub menuView_DropDownItemClicked(ByVal sender As Object, ByVal e As C1.Win.C1Command.ClickEventArgs) Dim nd = TryCast(e.CallerLink.Command.UserData, System.Xml.XmlNode) If nd IsNot Nothing Then ' load view definition from XML c1FlexPivotPage1.ViewDefinition = nd.OuterXml ' show current view name in status bar c1FlexPivotPage1.LabelStatus.Text = nd.Attributes("id").Value End If End Sub
private void menuView_DropDownItemClicked(object sender, C1.Win.C1Command.ClickEventArgs e) { var nd = e.CallerLink.Command.UserData as System.Xml.XmlNode; if (nd != null) { // load view definition from XML c1FlexPivotPage1.ViewDefinition = nd.OuterXml; // show current view name in status bar c1FlexPivotPage1.LabelStatus.Text = nd.Attributes["id"].Value; } }
' add new view menu to C1FlexPivotPage toolstrip Dim menuLink = New C1.Win.C1Command.C1CommandLink(menuView) c1FlexPivotPage1.ToolBar.CommandLinks.Insert(3, menuLink)
// add new view menu to C1FlexPivotPage toolstrip var menuLink = new C1.Win.C1Command.C1CommandLink(menuView); c1FlexPivotPage1.ToolBar.CommandLinks.Insert(3, menuLink);
Dim collapseAllView As C1.Win.C1Command.C1Command
C1.Win.C1Command.C1Command collapseAllView;
' add collapseall menu to C1FlexPivotPage toolstrip collapseAllView = New C1.Win.C1Command.C1Command() collapseAllView.Text = "&CollapseAll" collapseAllView.Image = My.Resources.CollapseAll AddHandler collapseAllView.Click, AddressOf collapseAllView_Click Dim collapseAllViewLink = New C1.Win.C1Command.C1CommandLink(collapseAllView) c1FlexPivotPage1.ToolBar.CommandLinks.Add(collapseAllViewLink)
// add collapseall menu to C1FlexPivotPage toolstrip collapseAllView = new C1.Win.C1Command.C1Command(); collapseAllView.Text = "&CollapseAll"; collapseAllView.Image = Properties.Resources.CollapseAll; collapseAllView.Click += collapseAllView_Click; C1.Win.C1Command.C1CommandLink collapseAllViewLink = new C1.Win.C1Command.C1CommandLink(collapseAllView); c1FlexPivotPage1.ToolBar.CommandLinks.Add(collapseAllViewLink);
Private Sub collapseAllView_Click(ByVal sender As Object, ByVal e As EventArgs) c1FlexPivotPage1.FlexPivotGrid.CollapseAllCols() c1FlexPivotPage1.FlexPivotGrid.CollapseAllRows() End Sub
private void collapseAllView_Click(object sender, C1.Win.C1Command.ClickEventArgs e) { c1FlexPivotPage1.FlexPivotGrid.CollapseAllCols(); c1FlexPivotPage1.FlexPivotGrid.CollapseAllRows(); }
AddHandler c1FlexPivotPage1.Updated, AddressOf c1FlexPivotPage1_Updated
c1FlexPivotPage1.Updated += c1FlexPivotPage1_Updated;
Private Sub c1FlexPivotPage1_Updated(ByVal sender As Object, ByVal e As EventArgs) ' clear report name after user made any changes c1FlexPivotPage1.LabelStatus.Text = String.Empty ' update button status of collapseAllView. If (c1FlexPivotPage1.ShowTotalsColumns = C1.FlexPivot.ShowTotals.Subtotals Or c1FlexPivotPage1.ShowTotalsRows = C1.FlexPivot.ShowTotals.Subtotals) Then collapseAllView.Enabled = True Else collapseAllView.Enabled = False End If End Sub
private void c1FlexPivotPage1_Updated(object sender, EventArgs e) { // clear report name after user made any changes c1FlexPivotPage1.LabelStatus.Text = string.Empty; // update button status of collapseAllView. if (c1FlexPivotPage1.ShowTotalsColumns == C1.FlexPivot.ShowTotals.Subtotals || c1FlexPivotPage1.ShowTotalsRows == C1.FlexPivot.ShowTotals.Subtotals) collapseAllView.Enabled = true; else collapseAllView.Enabled = false; }
