ComponentOne FlexPivot for WinForms
Quick Start: FlexPivot for WinForms / Using FlexPivot Controls with C1DataEngine / Step 2: Configuring FlexPivotPage Control and DataEngine
In This Topic
    Step 2: Configuring FlexPivotPage Control and DataEngine
    In This Topic

    In the previous step, you created a basic Windows Forms application and added FlexPivotPage control to it. In this step, you begin with configuring the FlexPivotPage control and C1DataEngine and connecting them to data.

    To configure the FlexPivotPage control and C1DataEngine and connect them with data, perform the following steps. 

    1. Switch to the code view i.e. Form1.cs and initialize workspace within the form's constructor.
      flexPivotPage.FlexPivotPanel.Workspace.Init(path)
      
      flexPivotPage.FlexPivotPanel.Workspace.Init(path);
      
    2. Initialize full path to the folder where the DataEngine stores data in files, and an SQL connection above the Form's constructor using the following code.
      Dim path As String = Environment.GetFolderPath(Environment.SpecialFolder.Personal) & "\ComponentOne Samples\Common"
      Dim conn As OleDbConnection = New OleDbConnection()
      
      string path = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + @"\ComponentOne Samples\Common";
      OleDbConnection conn = new OleDbConnection();             
      

      Initially, the DataEngine is empty but it automatically fills with files as and when the data is added to it.

    3. Initialize a standard connection string to the database file being used.
      Private Function GetConnectionString() As String
          Dim path As String = Environment.GetFolderPath(Environment.SpecialFolder.Personal) & "\ComponentOne Samples\Common"
          Dim conn As String = "provider=Microsoft.ACE.OLEDB.12.0;data source={0}\c1nwind.mdb;"
          Return String.Format(conn, path)
      End Function
      
      static string GetConnectionString()
      {
          string path = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + @"\ComponentOne Samples\Common";
          string conn = @"provider=Microsoft.ACE.OLEDB.12.0;data source={0}\c1nwind.mdb;";
          return string.Format(conn, path);
      }
      
    4. Switch to the Design view and subscribe Form1_Load event from the Properties window. 
    5. Add the following code to the event handler created for Form1_Load event in the code view.  
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
          conn.ConnectionString = GetConnectionString()
          conn.Open()
          Dim command = New OleDbCommand("Select * from Invoices", conn)
          Dim connector = New C1.DataEngine.DbConnector(flexPivotPage.FlexPivotPanel.Workspace, conn, command)
          connector.GetData("invoices")
          flexPivotPage.FlexPivotPanel.ConnectDataEngine("Invoices")
      End Sub
      
      private void Form1_Load(object sender, EventArgs e)
      {
          conn.ConnectionString = GetConnectionString();
          conn.Open();        
          var command = new OleDbCommand("Select * from invoices", conn);
          var connector = new C1.DataEngine.DbConnector(flexPivotPage.FlexPivotPanel.Workspace, conn, command);
          connector.GetData("invoices");
          flexPivotPage.FlexPivotPanel.ConnectDataEngine("invoices");
      }
      

    With this, you have successfully connected the FlexPivotPage control and DataEngine to data. 

    Note: WinForms .NET Edition does not include rich design-time support yet. We will enhance it in future releases.