ComponentOne True DBGrid for WinForms
Setting Default Values for New Rows
True DBGrid for WinForms Task-Based Help > 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.

Complete the following steps:

  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:

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

    To write code in Visual Basic

    Visual Basic
    Copy Code
    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
    

    To write code in C#

    C#
    Copy Code
    private void c1TrueDBGrid1_OnAddNew(object sender, System.EventArgs e)
    {
        this.c1TrueDBGrid1.Columns["Country"].Value = "United States";
    }
    

What You've Accomplished

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