windowsforms-devexpress-dot-xtraverticalgrid-dot-vgridcontrolbase-dot-moverow-x28-devexpress-dot-xtraverticalgrid-dot-rows-dot-baserow-devexpress-dot-xtraverticalgrid-dot-rows-dot-baserow-system-dot-boolean-x29.md
Moves the specified row to the position specified.
Namespace : DevExpress.XtraVerticalGrid
Assembly : DevExpress.XtraVerticalGrid.v25.2.dll
NuGet Packages : DevExpress.Win.Navigation, DevExpress.Win.VerticalGrid
public void MoveRow(
BaseRow source,
BaseRow destinationRow,
bool insertBefore
)
Public Sub MoveRow(
source As BaseRow,
destinationRow As BaseRow,
insertBefore As Boolean
)
| Name | Type | Description |
|---|---|---|
| source | BaseRow |
A BaseRow descendant that represents the row moved.
| | destinationRow | BaseRow |
A BaseRow descendant that represents the row before which the source row should be moved or the parent row whose child row collection it should be appended to.
| | insertBefore | Boolean |
true if the source row should be moved before the destination row; false if the source row should be appended to the child rows collection of the destination row.
|
The MoveRow method moves the row to the specified position within the vertical grid. Note that child rows (if any) are moved too.
Calling the MoveRow method has no effect in the instances listed below:
If the dest parameter is a null reference, the source row is appended to the grid’s VGridControlBase.Rows collection.
Note
The MoveRow method moves the row regardless of its VGridOptionsRow.AllowMove option state.
The following sample code sorts the “Software” child rows alphabetically in ascending order by their captions . The SortRows method searches the child rows list for the row with the smallest caption. It then moves this row to the front of the child row list. The VGridControlBase.MoveRow method is used for this purpose. Then it searches the remaining rows for the next smallest row, moves it into the list’s second position. The algorithm continues searching the shrinking list of unsorted rows, picking out the smallest and moving it to the end of the sorted section at the front of the child rows list. When it has moved every row into its final position, the algorithm stops.
The image below shows the result.
using DevExpress.XtraVerticalGrid.Rows;
// ...
private void SortRows(){
for(int i = 0; i < Software.ChildRows.Count - 1; i++){
BaseRow row = Software.ChildRows[i];
for(int j = i; j < Software.ChildRows.Count - 1; j++){
if (Software.ChildRows[j + 1].Properties.Caption.CompareTo(
row.Properties.Caption) < 0){
row = Software.ChildRows[j + 1];
}
}
vGridControl1.MoveRow(row, Software.ChildRows[i], true);
}
}
Imports DevExpress.XtraVerticalGrid.Rows
' ...
Private Sub SortRows()
Dim i, j As Integer
For i = 0 To i < Software.ChildRows.Count - 1
Dim row As BaseRow = Software.ChildRows(i)
For j = i To j < Software.ChildRows.Count - 1
If Software.ChildRows(j + 1).Properties.Caption.CompareTo( _
row.Properties.Caption) < 0 Then
row = Software.ChildRows(j + 1)
End If
Next j
VGridControl1.MoveRow(row, Software.ChildRows(i), True)
Next i
End Sub
See Also