Ejemplo n.º 1
0
        public static void SelectAndScrollInView <Item>(NSOutlineView treeView, Item[] items,
                                                        Func <Item, Item> parentGetter) where Item : NSObject
        {
            var rows = new List <uint> ();

            foreach (var item in items)
            {
                var rowIdx = treeView.RowForItem(item);
                if (rowIdx < 0)
                {
                    var stack = new Stack <Item>();
                    for (var i = parentGetter(item); i != null; i = parentGetter(i))
                    {
                        stack.Push(i);
                    }
                    while (stack.Count > 0)
                    {
                        treeView.ExpandItem(stack.Pop());
                    }
                    rowIdx = treeView.RowForItem(item);
                }
                if (rowIdx >= 0)
                {
                    rows.Add((uint)rowIdx);
                }
            }
            treeView.SelectRows(
                NSIndexSet.FromArray(rows.ToArray()),
                byExtendingSelection: false
                );
            if (rows.Count > 0)
            {
                treeView.ScrollRowToVisible((nint)rows[0]);
            }
        }