ComponentOne FlexPivot for WinForms
Binding FlexPivot to Data Source in Code
Quick Start: FlexPivot for WinForms > Using FlexPivot Controls with Data Source > Binding FlexPivot to Data Source in Code

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 C1FlexPivotPage 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()
    // load data
    var da = new OleDbDataAdapter("select * from invoices", GetConnectionString());
    var dt = new DataTable();
  5. Bind the FlexPivotPage control to the data source using DataSource property of C1FlexPivotPage class in the Form's constructor.
    ' bind data
    Me.C1FlexPivotPage1.DataSource = dt
    // bind data
    this.c1FlexPivotPage1.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.

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