ComponentOne True DBGrid for .NET (2.0) Search HelpCentral 

Setting Default Values for New Rows

To set default values for new rows, set the column's Value property in the OnAddNew event. This is useful if adding multiple rows with similar information.

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.   Add the following OnAddNew event to the form:

·      Visual Basic

Private Sub C1TrueDBGrid1_OnAddNew(ByVal sender As Object, ByVal e As System.EventArgs) Handles C1TrueDBGrid1.OnAddNew

    Me.C1TrueDBGrid1.Columns("Country").Value = "United States"

End Sub

·      C#

private void c1TrueDBGrid1_OnAddNew(object sender, System.EventArgs e)

{

    this.c1TrueDBGrid1.Columns["Country"].Value = "United States";

}

·      Delphi

procedure C1TrueDBGrid1_OnAddNew(sender: object; e: SystemEventArgs);

begin

  Self.C1TrueDBGrid1.Columns['Country'].Value := 'United States';

end;

This topic illustrates the following:

The value in the Country column automatically adds United States when a new row is added.


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