internal protected virtual void SiteNode(TreeGridNode node) { //TO_DO: Raise exception if parent node is not the root or is not sited. int rowIndex = -1; TreeGridNode currentRow; node._grid = this; if (node.Parent != null && node.Parent.IsRoot == false) { // row is a child Debug.Assert(node.Parent != null && node.Parent.IsExpanded == true); if (node.Index > 0) { currentRow = node.Parent.Nodes[node.Index - 1]; } else { currentRow = node.Parent; } } else { // row is being added to the root if (node.Index > 0) { currentRow = node.Parent.Nodes[node.Index - 1]; } else { currentRow = null; } } if (currentRow != null) { while (currentRow.Level >= node.Level) { if (currentRow.RowIndex < base.Rows.Count - 1) { currentRow = base.Rows[currentRow.RowIndex + 1] as TreeGridNode; Debug.Assert(currentRow != null); } else { // no more rows, site this node at the end. break; } } if (currentRow == node.Parent) { rowIndex = currentRow.RowIndex + 1; } else if (currentRow.Level < node.Level) { rowIndex = currentRow.RowIndex; } else { rowIndex = currentRow.RowIndex + 1; } } else { rowIndex = 0; } Debug.Assert(rowIndex != -1); this.SiteNode(node, rowIndex); Debug.Assert(node.IsSited); if (node.IsExpanded) { // add all child rows to display foreach (TreeGridNode childNode in node.Nodes) { //TO_DO: could use the more efficient SiteRow with index. this.SiteNode(childNode); } } }