ComponentOne True DBGrid for WinForms
Data Binding / Creating an Unbound Grid
In This Topic
    Creating an Unbound Grid
    In This Topic

    True DBGrid for WinForms can display data without being bound to a DataSource. Creating an unbound grid can be done in a few steps.

    To create an unbound grid, complete the following:

    1. Begin by creating your columns. This can be done either in the designer or in code. For more information on creating columns, see Creating Unbound Columns.

      To write code in Visual Basic

      Visual Basic
      Copy Code
      Me.C1TrueDBGrid1.Columns.Add(New C1.Win.C1TrueDBGrid.C1DataColumn("FirstName", GetType(String)))
      Me.C1TrueDBGrid1.Columns.Add(New C1.Win.C1TrueDBGrid.C1DataColumn("LastName", GetType(String)))
      Me.C1TrueDBGrid1.Columns.Add(New C1.Win.C1TrueDbGrid.C1DataColumn("DateOfBirth", GetType(DateTime)))
      

      To write code in C#

      C#
      Copy Code
      this.c1TrueDBGrid1.Columns.Add(new C1.Win.C1TrueDBGrid.C1DataColumn("FirstName",typeof(string)));
      this.c1TrueDBGrid1.Columns.Add(new C1.Win.C1TrueDBGrid.C1DataColumn("LateName",typeof(string)));
      this.c1TrueDBGrid1.Columns.Add(new C1.Win.C1TrueDBGrid.C1DataColumn("DateOfBirth",typeof(DateTime)));
      
    2. Call the SetDataBinding method with no arguments.

      To write code in Visual Basic

      Visual Basic
      Copy Code
      Me.C1TrueDBGrid1.SetDataBinding()
      

      To write code in C#

      C#
      Copy Code
      this.c1TrueDBGrid1.SetDataBinding();
      
    3. Use the AddRow or AddRows method to populate the grid.

      To write code in Visual Basic

      Visual Basic
      Copy Code
      Me.C1TrueDBGrid1.AddRow("John;Doe;11/29/1985")
      Me.C1TrueDBGrid1.AddRow("Jane;Doe;7/12/1980")
       
      Dim index As Integer = Me.C1TrueDBGrid1.AddRows(2)
      Dim i As Integer
      For i = index To 1
          Me.C1TrueDBGrid1(i, "FirstName") = "Joe"
          Me.C1TrueDBGrid1(i, "LastName") = "Doe"
          Me.C1TrueDBGrid1(i, "DateOfBirth") = New DateTime(2000, 1, 15)
      Next i
      

      To write code in C#

      C#
      Copy Code
      this.c1TrueDBGrid1.AddRow("John;Doe;11/29/1985");
      this.c1TrueDBGrid1.AddRow("Jane;Doe;7/12/1980");
       
      int index = this.c1TrueDBGrid1.AddRows(2);
      for(int i=index; i < 2; i++)
      {
          this.c1TrueDBGrid1[i,"FirstName"] = "Joe";
          this.c1TrueDBGrid1[i, "LastName"] = "Doe";
          this.c1TrueDBGrid1[i, "DateOfBirth"] = new DateTime(2000,1, 15);
      }
      

    You have successfully created an unbound grid.

    See Also