ComponentOne True DBGrid for .NET (2.0) Search HelpCentral 

Adding a New Row to C1TrueDBGrid

To add a new row to C1TrueDBGrid, use the AllowAddNew property and the UpdateData method.

1.   Set the AllowAddNew property to True.

In the Designer

Locate the AllowAddNew property in the Properties window and set it to True.

In Code

Add the following code to the Form_Load event:

·      Visual Basic

Me.C1TrueDBGrid1.AllowAddNew = True

·      C#

this.c1TrueDBGrid1.AllowAddNew = true;

·      Delphi

Self.C1TrueDBGrid1.AllowAddNew := True;

2.   Move to the last column in the grid by adding the following code to the Form_Load event:

·      Visual Basic

Me.C1TrueDBGrid1.MoveLast()

·      C#

this.c1TrueDBGrid.MoveLast();

·      Delphi

Self.C1TrueDBGrid.MoveLast;

3.   Select the new row:

·      Visual Basic

Me.C1TrueDBGrid1.Row = Me.C1TrueDBGrid1.Row + 1

Me.C1TrueDBGrid1.Select()

·      C#

this.c1TrueDBGrid1.Row = this.c1TrueDBGrid1.Row + 1;

this.c1TrueDBGrid1.Select();

·      Delphi

Self.C1TrueDBGrid1.Row := Self.C1TrueDBGrid1.Row + 1;

Self.C1TrueDBGrid1.Select;

4.   Assign values to the new cells in the first three columns:

·      Visual Basic

Me.C1TrueDBGrid1.Columns(0).Text = "New Row"

Me.C1TrueDBGrid1.Columns(1).Text = "New Row"

Me.C1TrueDBGrid1.Columns(2).Text = "New Row"

·      C#

this.c1TrueDBGrid1.Columns[0].Text = "New Row";

this.c1TrueDBGrid1.Columns[1].Text = "New Row";

this.c1TrueDBGrid1.Columns[2].Text = "New Row";

·      Delphi

Self.C1TrueDBGrid1.Columns[0].Text := 'New Row';

Self.C1TrueDBGrid1.Columns[1].Text := 'New Row';

Self.C1TrueDBGrid1.Columns[2].Text := 'New Row';

5.   Update the data to the dataset:

·      Visual Basic

Me.C1TrueDBGrid1.UpdateData()

·      C#

this.c1TrueDBGrid1.UpdateData();

·      Delphi

Self.C1TrueDBGrid1.UpdateData;

This topic illustrates the following:

In this example, a new row has been added to the TDBGDemo.mdb.

There is also a SelectedRows property which points to a collection which contains a reference to all the selected rows in the Grid.


Selecting a Row

Accessing the Values of the Selected Rows in the Grid


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