ComponentOne FlexPivot for WinForms
Quick Start: FlexPivot for WinForms / Using FlexPivot Controls with Data Source / Binding FlexPivot to Data Source in Code
In This Topic
    Binding FlexPivot to Data Source in Code
    In This Topic

    You can also bind the FlexPivot controls to a data source kept locally at your machine in code. Follow the given steps to bind the FlexPivotPage control to data source (c1nwind.mdb) in code.

    In Code

    1. Create a Windows Forms Application project in Visual Studio.
    2. Drag-and-drop FlexPivotPage control to the Form.
    3. Switch to the code view and add the following code to initialize a standard connection string.
      Private Shared Function GetConnectionString() As String
          Dim path As String = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "\ComponentOne Samples\Common"
          Dim conn As String = "provider=microsoft.jet.oledb.4.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.jet.oledb.4.0;data source={0}\c1nwind.mdb;";
          return string.Format(conn, path);
      }
      

      This code creates a connection with the c1nwind.mdb database file installed on your system at Documents\ComponentOne Samples\Common location on your system.

    4. Add the following code in the Form's constructor to fetch data from the data source through Oledb adapters.
      ' load data
      Dim da = New OleDbDataAdapter("select * from invoices", GetConnectionString())
      Dim dt = New DataTable()
      da.Fill(dt)
      
      // load data
      var da = new OleDbDataAdapter("select * from invoices", GetConnectionString());
      var dt = new DataTable();
      da.Fill(dt);
      
    5. Bind the FlexPivotPage control to the data source using DataSource property of FlexPivotPage class in the Form's constructor.
      ' bind data
      Me.FlexPivotPage1.DataSource = dt
      
      // bind data
      this.flexPivotPage1.DataSource = dt;
      
    6. Press F5 to run the application. FlexPivotPage is now connected to the c1nwind.mdb file with various data fields available in the FlexPivotPanel.

      FlexPivot_view

    You can now create different views by dragging the data fields to Rows, Columns and Values list for data analysis.