ComponentOne True DBGrid for WinForms
True DBGrid for WinForms Tutorials / Tutorial 20: Displaying Multiple Data Views
In This Topic
    Tutorial 20: Displaying Multiple Data Views
    In This Topic

    In this tutorial, you will learn how to use the grid's DataView property to display data in uncommon display formats such as Inverted View, GroupBy View, and Form View.

    Complete the following steps:

    1. Start with the project created in Tutorial 1: Binding True DBGrid to a DataSet.
    2. Add a ComboBox control (ComboBox1) to the project, and set its Text property to "Data View".
    3. In the Properties window, open up the List editor for the ComboBox by clicking on the ellipsis button next to the Items property. In this editor add the following items:
      Normal
      Inverted
      Form
      GroupBy
      MultipleLines
      Hierarchical
    4. Now add the following code to the existing code in the Load event of Form1:

      To write code in Visual Basic

      Visual Basic
      Copy Code
      Me.C1TrueDBGrid1.DataView = C1.Win.C1TrueDBGrid.DataViewEnum.Normal
      Me.ComboBox1.SelectedIndex = 0
      

      To write code in C#

      C#
      Copy Code
      this.c1TrueDBGrid1.DataView = C1.Win.C1TrueDBGrid.DataViewEnum.Normal;
      this.comboBox1.SelectedIndex = 0;
      
    5. Now add the following code to the SelectedIndexChanged event of ComboBox1. It changes the DataView property of the grid for each value the user selects in the ComboBox:

      To write code in Visual Basic

      Visual Basic
      Copy Code
      Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
          Select Case ComboBox1.SelectedItem
              Case "Normal"
                  Me.C1TrueDBGrid1.DataView = C1.Win.C1TrueDBGrid.DataViewEnum.Normal
              Case "Inverted"
                  Me.C1TrueDBGrid1.DataView = C1.Win.C1TrueDBGrid.DataViewEnum.Inverted
              Case "Form"
                  Me.C1TrueDBGrid1.DataView = C1.Win.C1TrueDBGrid.DataViewEnum.Form
              Case "GroupBy"
                  Me.C1TrueDBGrid1.DataView = C1.Win.C1TrueDBGrid.DataViewEnum.GroupBy
              Case "MultipleLines"
                  Me.C1TrueDBGrid1.DataView = C1.Win.C1TrueDBGrid.DataViewEnum.MultipleLines
              Case "Hierarchical"
                  MessageBox.Show ("Hierarchical View can't be set at run time. Please see the Hierarchical Display tutorial")
           End Select
      End Sub
      

      To write code in C#

      C#
      Copy Code
      private void ComboBox1_SelectedIndexChanged(object sender,  System.EventArgs e)  
      {
          switch (ComboBox1.SelectedItem) 
          { 
              case "Normal":
                  this.c1TrueDBGrid1.DataView = C1.Win.C1TrueDBGrid.DataViewEnum.Normal;
                  break;
              case "Inverted":
                  this.c1TrueDBGrid1.DataView = C1.Win.C1TrueDBGrid.DataViewEnum.Inverted;
                  break;
              case "Form":
                  this.c1TrueDBGrid1.DataView = C1.Win.C1TrueDBGrid.DataViewEnum.Form;
                  break;
              case "GroupBy":
                  this.c1TrueDBGrid1.DataView = C1.Win.C1TrueDBGrid.DataViewEnum.GroupBy;
                  break;
              case "MultipleLines":
                  this.c1TrueDBGrid1.DataView = C1.Win.C1TrueDBGrid.DataViewEnum.MultipleLines;
                  break;
              case "Hierarchical";
                  MessageBox.Show ("Hierarchical View can't be set at run time. Please see the Hierarchical Display tutorial");
                  break;
           }
      }
      

    Run the program and observe the following:

    You've successfully completed displaying multiple data views; this concludes the tutorial.