Back to Devexpress

VGridRows.Add(BaseRow) Method

windowsforms-devexpress-dot-xtraverticalgrid-dot-rows-dot-vgridrows-dot-add-x28-devexpress-dot-xtraverticalgrid-dot-rows-dot-baserow-x29.md

latest6.7 KB
Original Source

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.v25.2.dll

NuGet Packages : DevExpress.Win.Navigation, DevExpress.Win.VerticalGrid

Declaration

csharp
public virtual int Add(
    BaseRow row
)
vb
Public Overridable Function Add(
    row As BaseRow
) As Integer

Parameters

NameTypeDescription
rowBaseRow

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

|

Returns

TypeDescription
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 example below creates a row. The Rows collection’s Add(BaseRow) method is called to add this row to the control. The row is added as a top-level row or as JobDescription row’s child depending on a condition.

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

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

    if (vGridControl1.Rows["JobDescription"].Visible) 
        // Append the row to the JobDescription row's child row collection.
        vGridControl1.Rows["JobDescription"].ChildRows.Add(row); 
    else
        // Append the row to the top-level row collection.
        vGridControl1.Rows.Add(row); 
}
vb
Imports DevExpress.XtraVerticalGrid
Imports DevExpress.XtraVerticalGrid.Rows

Private Sub AddRowRange()
    ' Create a row bound to a specific field and specify its caption.
    Dim Row As New EditorRow("job_lvl")
    Row.Properties.Caption = "Job Level"
    If VGridControl1.Rows("JobDescription").Visible Then
        ' Append the row to the JobDescription row's child row collection.
        VGridControl1.Rows("JobDescription").ChildRows.Add(Row)
    Else
        ' Append the row to the top-level row collection.
        VGridControl1.Rows.Add(Row)
    End If
End Sub

The following code snippet (auto-collected from DevExpress Examples) contains a reference 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.

winforms-property-grid-create-rows/CS/AddRowsRuntime/Form1.cs#L28

csharp
rowLastName.Properties.Caption = "Last name";
propertyGridControl1.Rows.Add(rowLastName);
CategoryRow rowCategory = new CategoryRow("Address");

winforms-property-grid-create-rows/VB/AddRowsRuntime/Form1.vb#L28

vb
rowLastName.Properties.Caption = "Last name"
propertyGridControl1.Rows.Add(rowLastName)
Dim rowCategory As CategoryRow = New CategoryRow("Address")

See Also

AddRange(BaseRow[])

Insert(BaseRow, Int32)

BaseRow

Rows

VGridRows Class

VGridRows Members

DevExpress.XtraVerticalGrid.Rows Namespace