Пример #1
0
        public void Build(object root)
        {
            this.root = root;
            //create set of selected and checked nodes
            var selected = new HashSet <object>();
            var check    = new HashSet <object>();

            foreach (var i in SelectedItemIndexes)
            {
                selected.Add(nodes[i]);
            }

            foreach (var i in CheckedItemIndex)
            {
                check.Add(nodes[i]);
            }

            //
            nodes.Clear();
            levels.Clear();
            SelectedItemIndexes.Clear();
            CheckedItemIndex.Clear();

            //build list of expanded nodes
            if (ShowRootNode)
            {
                AddNode(root, 0);
            }
            else
            {
                AddNodeChildren(root, 0);
            }
            //restore indexes of selected and checked nodes
            var newExpanded = new HashSet <object>();

            hasChildren = new BitArray(nodes.Count);

            for (int i = 0; i < nodes.Count; i++)
            {
                var node = nodes[i];
                if (selected.Contains(node))
                {
                    SelectedItemIndexes.Add(i);
                }
                if (check.Contains(node))
                {
                    CheckedItemIndex.Add(i);
                }
                if (expandedNodes.Contains(node))
                {
                    newExpanded.Add(node);
                }
                hasChildren[i] = GetNodeChildren(nodes[i]).Cast <object>().Any();
            }

            expandedNodes = newExpanded;
            ItemCount     = nodes.Count;
            base.Build();
        }
Пример #2
0
        public override bool CheckItem(int itemIndex)
        {
            if (GetItemChecked(itemIndex))
            {
                return(true);
            }

            Invalidate();

            if (CanCheckItem(itemIndex))
            {
                if (NodeCheckStateNeeded == null)//add to CheckedItemIndex only if handler of NodeCheckStateNeeded is not assigned
                {
                    CheckedItemIndex.Add(itemIndex);
                }
                OnItemChecked(itemIndex);
                return(true);
            }

            return(false);
        }