public void ScrollNodeIntoView(TreeGridNodeReference node) { DoRowLayoutUntilValid(); var visibleRow = this.visibleRows.FirstOrDefault(r => r.NodeReference.Equals(node)); if (visibleRow == null) { node.ExpandParents(); int flatIndex; if (node.TryGetFlatIndex(out flatIndex)) { this.TopItemIndex = Math.Max(0, flatIndex - this.visibleRows.Count / 3); } } }
public TreeGridRow SelectNode(TreeGridNodeReference node, SelectionOperation op) { int nodeIndex; using (new SelectionChangeSuppressor(this)) { if (!node.TryGetFlatIndex(out nodeIndex)) { Debug.Fail("Selected node must be exposed (can't be in a collapsed parent)!"); return null; } if (op == SelectionOperation.SelectOne) { ClearSelection(false); AddNodeToSelection(node); this.selectionAnchorIndex = nodeIndex; } else if (op == SelectionOperation.Toggle) { if (!this.selectedNodeReferences.ContainsKey(node)) { AddNodeToSelection(node); } else { RemoveNodeFromSelection(node); } if (this.selectionAnchorIndex == -1) { this.selectionAnchorIndex = nodeIndex; } } else if (op == SelectionOperation.Add) { if (!this.selectedNodeReferences.ContainsKey(node)) { AddNodeToSelection(node); if (this.selectionAnchorIndex == -1) { this.selectionAnchorIndex = nodeIndex; } } } else if (op == SelectionOperation.ExtendTo) { if (this.selectionAnchorIndex != -1) { int min = Math.Min(this.selectionAnchorIndex, nodeIndex); int max = Math.Max(this.selectionAnchorIndex, nodeIndex); ClearSelection(false); using (var nodeToSelect = this.rootNode.CreateNodeReference(min)) { while (nodeToSelect != null && (min <= max)) { AddNodeToSelection(nodeToSelect); if (!nodeToSelect.MoveToNextFlatNode()) { break; } min += 1; } } } } TreeGridRow newCurrentRow = null; foreach (var row in this.visibleRows) { row.IsSelected = this.selectedNodeReferences.ContainsKey(row.NodeReference); if (row.NodeReference.Equals(this.currentNode)) { newCurrentRow = row; } } if (newCurrentRow != null) { newCurrentRow.IsCurrent = true; } return newCurrentRow; } }