To add a new row to C1TrueDBGrid, use the AllowAddNew property and the UpdateData method.
Complete the following steps:
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:
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
Me.C1TrueDBGrid1.AllowAddNew = True |
To write code in C#
C# |
Copy Code
|
---|---|
this.c1TrueDBGrid1.AllowAddNew = true; |
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
Me.C1TrueDBGrid1.MoveLast() |
To write code in C#
C# |
Copy Code
|
---|---|
this.c1TrueDBGrid.MoveLast(); |
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
Me.C1TrueDBGrid1.Row = Me.C1TrueDBGrid1.Row + 1 Me.C1TrueDBGrid1.Select() |
To write code in C#
C# |
Copy Code
|
---|---|
this.c1TrueDBGrid1.Row = this.c1TrueDBGrid1.Row + 1; this.c1TrueDBGrid1.Select(); |
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
Me.C1TrueDBGrid1.Columns(0).Text = "New Row" Me.C1TrueDBGrid1.Columns(1).Text = "New Row" Me.C1TrueDBGrid1.Columns(2).Text = "New Row" |
To write code in C#
C# |
Copy Code
|
---|---|
this.c1TrueDBGrid1.Columns[0].Text = "New Row"; this.c1TrueDBGrid1.Columns[1].Text = "New Row"; this.c1TrueDBGrid1.Columns[2].Text = "New Row"; |
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
Me.C1TrueDBGrid1.UpdateData() |
To write code in C#
C# |
Copy Code
|
---|---|
this.c1TrueDBGrid1.UpdateData(); |
In this example, a new row has been added to the C1NWind.mdb:
There is also a SelectedRows property which points to a collection which contains a reference to all the selected rows in the grid.