Skip to main content
A newer version of this page is available. .

VGridRows.Add(BaseRow) Method

Adds a specific row to the end of the rows collection and returns its index.

Namespace: DevExpress.XtraVerticalGrid.Rows

Assembly: DevExpress.XtraVerticalGrid.v19.2.dll

Declaration

public virtual int Add(
    BaseRow row
)

Parameters

Name Type Description
row BaseRow

An instance of the BaseRow class descendant representing the row to add.

Returns

Type Description
Int32

The zero-based index at which a specific row object has been added to the collection.

Remarks

Use the Add method to append the existing row object derived from the BaseRow class to the end of the rows collection represented by the VGridRows object.

The Add method returns the index of the newly added row object in the rows collection. The returned index is zero-based.

To add a set of row objects to the rows collection, it is best to use the VGridRows.AddRange method. If you choose to use the Add method to add a number of rows to the rows collection, use the VGridControlBase.BeginUpdate method to prevent the grid from being repainted each time an item is added. Use the VGridControlBase.EndUpdate method to repaint the control after all items have been added. You can use the VGridRows.Insert method to specify the location where a row object is added.

To remove the row you previously added, use its Dispose method or the VGridRows.Remove method of the collection. Use the Clear() method if you want to remove all rows from the collection.

Example

The following example creates a row object of the EditorRow type and uses the VGridRows.Add method to add the row either to the child rows collection of the JobDescription row or to the grid’s collection of top level rows depending upon the JobDescription row’s visibility.

using DevExpress.XtraVerticalGrid;
using DevExpress.XtraVerticalGrid.Rows;

private void AddRow() {
    // creating a row object bound to a specific field and specifying its caption
    EditorRow row = new EditorRow("job_lvl");
    row.Properties.Caption = "Job Level";

    if (vGridControl1.Rows["JobDescription"].Visible) 
        // appending the row to collection of JobDescription row's children
        vGridControl1.Rows["JobDescription"].ChildRows.Add(row); 
    else
        // appending the row to collection of top level rows
        vGridControl1.Rows.Add(row); 
}

The following code snippets (auto-collected from DevExpress Examples) contain references to the Add(BaseRow) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also