When you modify data in real time, you often call Row.Update() method. It helps the grid to perform the required operations to define new row position, compliance with filtering, grouping and hierarchy sorting criteria, etc. In addition to automatically moving a row, the grid provides a convenient API for changing its position.

The grid has two systems of calculating row location. The first of them displays only visible rows disregarding their hierarchy location and is available via Grid.Rows. The second one shows grid hierarchy disregarding row visibility and is available via Grid.Nodes / Row.Clildren. Every Row has some properties that specify its grid location.

Row propertyDescription
Row.ChildIndexIndex in parent Row.Clildren or in Grid.Nodes, if a row is one the top hierarchy level.
Row.VisibleIndexIndex in Grid.Rows if the row is visible.
Row.ChildrenList of all children of the row.
Row.VisibleChildrenList of visible children.
Row.VisibleChildIndexIndex in parent VisibleChildren container.

Considering all the above, you may move rows with Row.ChildIndex only if the grid is not sorted. This property has been selected because it defines row position in the grid disregarding hierarchy and visibility of previous rows.

Please see below two examples that move rows to the beginning or to the end of the parent row.

C# Copy imageCopy
public void MoveToTop(Row row)
{
    row.ChildIndex = 0;
}

public void MoveToBottom(Row row)
{
    Row parent = row.Parent;
    row.ChildIndex = parent != null
                         ? parent.Children.Count - 1
                         : row.Grid.Nodes.Count - 1;
}

Back to .Net Grid HowTo topics