ComponentOne True DBGrid for .NET (2.0) Search HelpCentral 

Displaying Data Without Binding to a DataSource

True DBGrid can now display data without being bound to a DataSource. Creating an unbound grid can be done in a few steps. To create an unbound grid:

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

·      Visual Basic

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)))

·      C#

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)));

·      Delphi

Self.C1TrueDBGrid1.Columns.Add(C1.Win.C1TrueDBGrid.C1DataColumn.Create('FirstName', TypeOf(string)));

Self.C1TrueDBGrid1.Columns.Add(C1.Win.C1TrueDBGrid.C1DataColumn.Create('LastName', TypeOf(string)));

Self.C1TrueDBGrid1.Columns.Add(C1.Win.C1TrueDBGrid.C1DataColumn.Create('DateOfBirth', TypeOf(DateTime)));

2.   Call the SetDataBinding method with no arguments.

·      Visual Basic

Me.C1TrueDBGrid1.SetDataBinding()

·      C#

this.c1TrueDBGrid1.SetDataBinding();

·      Delphi

Self.C1TrueDBGrid1.SetDataBinding;

3.   Use the AddRow or AddRows method to populate the grid.

·      Visual Basic

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

·      C#

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);

}

·      Delphi

Self.C1TrueDBGrid1.AddRow('John;Doe;11/29/1985');

Self.C1TrueDBGrid1.AddRow('Jane;Doe;7/12/1980');

index := Self.C1TrueDBGrid1.AddRows(2);

i := index;

while (i < 2) do

begin

  Self.C1TrueDBGrid1[i, 'FirstName'] := 'Joe';

  Self.C1TrueDBGrid1[i, 'LastName'] := 'Doe';

  Self.C1TrueDBGrid1[i, 'DateOfBirth'] := DateTime.Create(2000, 1, 15);

end;

You have now successfully created an unbound grid.


Send comments about this topic to ComponentOne.
Copyright © ComponentOne LLC. All rights reserved.