public void OnChecked()
 {
     if (!_isUpdating)
     {
         _isUpdating = true;
         CheckState checkState = _parentTree.Binding.ToggleCheckState(_item);
         if (_bindingTreeView.CheckBoxes)
         {
             this.StateImageKey = checkState.ToString();
         }
         _isUpdating = false;
     }
 }
Exemple #2
0
        private static CheckBoxState ConvertCheckState(CheckState checkState)
        {
            switch (checkState)
            {
            case CheckState.Checked:
                return(CheckBoxState.CheckedNormal);

            case CheckState.Partial:
                return(CheckBoxState.MixedNormal);

            default:
            case CheckState.Unchecked:
                return(CheckBoxState.UncheckedNormal);
            }
        }
 	private static CheckBoxState ConvertCheckState(CheckState checkState)
 	{
 		switch (checkState)
 		{
 			case CheckState.Checked:
 				return CheckBoxState.CheckedNormal;
 			case CheckState.Partial:
 				return CheckBoxState.MixedNormal;
 			default:
 			case CheckState.Unchecked:
 				return CheckBoxState.UncheckedNormal;
 		}
 	}
        private void UpdateDisplay(ImageList treeViewImageList)
        {
            // Remember the previous update state, and return to it afterward.
            var wasStillUpdating = _isUpdating;

            _isUpdating = true;

            if (this.TreeView != null)
            {
                this.TreeView.BeginUpdate();
            }

            // update all displayable attributes from the binding
            this.Text        = _parentTree.Binding.GetNodeText(_item);
            this.ToolTipText = _parentTree.Binding.GetTooltipText(_item);

            CheckState checkState = _parentTree.Binding.GetCheckState(_item);

            if (_bindingTreeView.CheckBoxes)
            {
                this.StateImageKey = checkState.ToString();
            }

            if (_parentTree.Binding.GetIsHighlighted(_item))
            {
                this.BackColor = System.Drawing.Color.FromArgb(124, 177, 221);
            }
            else
            {
                this.BackColor = System.Drawing.Color.Empty;
            }

            if (treeViewImageList != null)
            {
                var resolver        = _parentTree.Binding.GetResourceResolver(_item);
                var iconSet         = _parentTree.Binding.GetIconSet(_item);
                var imageCollection = treeViewImageList.Images;
                if (iconSet == null)
                {
                    this.ImageKey = string.Empty;
                }
                else
                {
                    try
                    {
                        var iconKey = iconSet.GetIconKey(_bindingTreeView.IconResourceSize, resolver);
                        if (!imageCollection.ContainsKey(iconKey))
                        {
                            imageCollection.Add(iconKey, iconSet.CreateIcon(_bindingTreeView.IconResourceSize, resolver));
                        }
                        this.ImageKey = iconKey;
                    }
                    catch (Exception e)
                    {
                        Platform.Log(LogLevel.Debug, e);
                        this.ImageKey = string.Empty;
                    }
                }

                this.SelectedImageKey = this.ImageKey;
            }

            // if the subtree was already built, we may need to rebuild it if it has changed
            if (_isSubTreeBuilt)
            {
                // rebuild the subtree only if the binding returns a different reference
                if (_parentTree.Binding.GetSubTree(_item) != _subtreeManager.Tree)
                {
                    RebuildSubTree();
                }
            }
            else
            {
                // add a dummy child so that we get a "plus" sign next to the node
                if (_parentTree.Binding.CanHaveSubTree(_item) && this.Nodes.Count == 0)
                {
                    this.Nodes.Add(new TreeNode(SR.MessageErrorRetrievingSubtree));
                }
            }

            if (this.TreeView != null)
            {
                this.TreeView.EndUpdate();
            }

            // check whether to start in expanded or collapsed state
            if (_parentTree.Binding.GetExpanded(_item))
            {
                this.Expand();
            }
            else
            {
                this.Collapse();
            }

            // Return the updating flag back to the previous update state, rather than setting it to null.
            _isUpdating = wasStillUpdating;
        }