| Task-Based Help > Creating Custom FlexPivot Application in Code > Creating Default View |
Data (view or table) added to the FlexPivotPage control can be visualized by creating views. You can create summarized views by dragging data fields into various lists at runtime as illustrated in Creating Different Views at Runtime topic. To create a default view that appears automatically when your FlexPivot application runs, you need to perform some design-time settings and add set the ViewDefinition property in code.
Complete the following steps to create an application that displays a default view with ProductName in the Rows list, Country in the Columns list, and ExtendedPrice in the Values list.

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load ' modify the connection string to make it work for the current user on this machine Me.InvoicesTableAdapter.Connection.ConnectionString = GetConnectionString() 'loads data into the table adapter Me.InvoicesTableAdapter.Fill(Me.C1NWindDataSet.Invoices) ' show default view: ' this assumes an application setting of type string called "DefaultView" Dim view = My.Settings.DefaultView If Not String.IsNullOrEmpty(view) Then c1FlexPivotPage1.ViewDefinition = view Else ' build default view now Dim fp = c1FlexPivotPage1.FlexPivotEngine fp.BeginUpdate() fp.RowFields.Add("ProductName") fp.ColumnFields.Add("Country") fp.ValueFields.Add("ExtendedPrice") fp.EndUpdate() End If End Sub
private void Form1_Load(object sender, EventArgs e) { //modify the connection string to make it work for the current user on this machine this.invoicesTableAdapter.Connection.ConnectionString = GetConnectionString(); //loads data into the table adapter this.invoicesTableAdapter.Fill(this.c1NWindDataSet.Invoices); // show default view: // this assumes an application setting of type string called "DefaultView" var view = Properties.Settings.Default.DefaultView; if(!string.IsNullOrEmpty(view)) { c1FlexPivotPage1.ViewDefinition = view; } else { // build default view var fp = c1FlexPivotPage1.FlexPivotEngine; fp.BeginUpdate(); fp.RowFields.Add("ProductName"); fp.ColumnFields.Add("Country"); fp.ValueFields.Add("ExtendedPrice"); fp.EndUpdate(); } }
'initializing the 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
//initializing the connection string 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); }
