[]
You can populate FlexPivot with data by binding the FlexPivotPage control with a data source. For this, you can use a data table or a data engine as the data source for binding to the FlexPivot. Let us discuss how you can bind the FlexPivot to a data table and a data engine in the following sections.
To bind the FlexPivot to a data table, follow these steps:
Establish a connection to the C1NWind database using the OLE DB provider connection string, as shown in the following code:
//Establish connection to database and fetch data
OleDbConnection oconn = new OleDbConnection();
oconn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=..\..\Documents\ComponentOne Samples\Common\C1NWind.mdb";
var da = new OleDbDataAdapter("select * from Invoices", oconn);
Fetch the data from the database to the data table using the following code:
var dt = new DataTable();
da.Fill(dt);
Bind the datatable to FlexPivot's C1PivotEngine using the FlexPivotPanel.C1PivotEngine property as shown in the following code:
flexPivotPage.FlexPivotPanel.C1PivotEngine.BeginUpdate();
flexPivotPage.DataSource = dt.DefaultView;
flexPivotPage.FlexPivotPanel.C1PivotEngine.EndUpdate();
To bind the FlexPivot to a data table, follow these steps:
Establish a connection to the C1NWind database using the OLE DB provider connection string, as shown in the following code:
//Establish connection to database and fetch data
OleDbConnection oconn = new OleDbConnection();
oconn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=..\..\Documents\ComponentOne Samples\Common\C1NWind.mdb";
var da = new OleDbDataAdapter("select * from Invoices", oconn);
Fetch the data from the database to the data table using the following code:
var dt = new DataTable();
da.Fill(dt);
dt.TableName = "Invoices";
Initialize the DataEngine workspace for storing DataEngine data using the following code:
string dataPath = Path.Combine(Directory.GetCurrentDirectory(), "Data");
//Storing DataEngine data
flexPivotPage.FlexPivotPanel.Workspace.Init(dataPath);
BindToDataEngine();
Import the data from the data table to the DataEngine's datatable using the following code:
//Import data in DataEngine datatable
C1.DataEngine.DbConnector.GetData(flexPivotPage.FlexPivotPanel.Workspace, dt.CreateDataReader(), dt.TableName);
Bind the datatable to FlexPivot's C1PivotEngine using the FlexPivotPanel.C1PivotEngine property as shown in the following code:
//Connect FlexPivot to DataEngine filled with data
var fPanel = flexPivotPage.FlexPivotPanel;
fPanel.C1PivotEngine.BeginUpdate();
fPanel.ConnectDataEngine(dt.TableName);
fPanel.C1PivotEngine.EndUpdate();