True DBGrid for WinForms | ComponentOne
Rows / Basic Operations
In This Topic
    Basic Operations
    In This Topic

    This topic discusses various basic operations which can be performed on a row in True DBGrid, such as adding, deleting and inserting a row.

    Add Row

    True DBGrid provides various ways to add a new row at runtime. In case of unbound mode, you can set any integer value in Count parameter of the AddRow property in C1TrueDBGrid class to set the number of rows to be displayed in the grid.

    Use the code below to add rows to the WinForms True DBGrid in both unbound and bound modes.

    // Add twelve rows
    c1TruedbGrid1.AddRows(12);
    
    c1TruedbGrid1.MoveLast();
    c1TruedbGrid1.Row = c1TruedbGrid1.Row + 1;
    c1TruedbGrid1.Select();
    c1TruedbGrid1.Columns[0].Text = "1";
    c1TruedbGrid1.Columns[1].Text = "New Row";
    c1TruedbGrid1.UpdateData();
    

    Delete Row

    To delete the current row from the grid, you can use the Delete method of the C1TrueDBGrid class. You can also remove the row from a specified index using RemoveAt method.

    Following code gives different approaches to delete row from the WinForms True DBGrid.

    C#
    Copy Code
    if (c1TruedbGrid1.Rows.Count > 0)
    {
      // Approach 1
      c1TruedbGrid1.Delete();
      // Approach 2
      c1TruedbGrid1.Rows.RemoveAt(c1TruedbGrid1.Row);
    }
    

    Insert Row

    To insert a row in True DBGrid at a specific location, you can use the NewRow method in Frame class. You can also use the InsertAt method of DataRowCollection class to insert a row at a particular index in the grid.

    Below code demonstrates how to insert a row at a particular position in the WinForms True DBGrid.

    C#
    Copy Code
    // Approach 1
    var row = c1TruedbGrid1.NewRow();
    // Approach 2
    c1TruedbGrid1.Rows.InsertAt(row,c1TruedbGrid1.Row);