Raccoom.Windows.Forms.TreeViewFolderBrowser.MarkNode C# (CSharp) Method

MarkNode() protected method

Set the text bold if there is a child node checked.
protected MarkNode ( TreeNodePath node ) : void
node TreeNodePath
return void
        protected internal virtual void MarkNode(TreeNodePath node)
        {
            if (_checkboxBehavior == CheckboxBehaviorMode.None) return;
              //
              if (node == null) return;
              // no path selected, no node could be marked
              if (folderList_.Count == 0)
              {
            try
            {
              if ((node.NodeFont != null) && (node.NodeFont.Bold))
              {
            node.NodeFont = Font;
              }
            }
            catch {}
            return;
              }
              // there are a few paths, so we have to check each against our node path
              string path = node.Path;
              //
              bool isBold = false;
              foreach (string s in folderList_)
              {
            // if path is equal, return
            if (s.Equals(path)) continue;
            // if path is substring, mark node bold, otherwise normal font is used
            if (s.IndexOf(path) != -1)
            {
              isBold = true;
              break;
            }
            else
            {
              isBold = false;
            }
              }
              //
              if (isBold)
              {
            node.NodeFont = boldFont_;
              }
              else
              {
            node.NodeFont = Font;
              }
        }

Usage Example

        /// <summary>
        /// Creates a tree node and add it to the <c>TreeNodeCollection</c>.
        /// </summary>
        /// <param name="text">The text displayed in the label of the tree node.</param>
        /// <param name="path">The path the node represents.</param>
        /// <param name="addDummyNode">True to add + sign, otherwise no + sign appears.</param>
        /// <param name="forceChecked">True to check node in each case, otherwise false to allow normal check against selected paths.</param>
        /// <param name="isSpecialFolder">Specifies if this node is a special folder. Special folders do not request data from the attached data provider.</param>
        /// <returns></returns>
        private TreeNodePath CreateTreeNode(string text, string path, bool addDummyNode, bool forceChecked, bool isSpecialFolder)
        {
            //
            TreeNodePath newNode = new TreeNodePath(text, isSpecialFolder);

            // path
            newNode.Path = path;

            //
            try
            {
                _treeView.SuppressCheckEvent(true);
                //
                if (forceChecked)
                {
                    newNode.Checked = true;
                }
                else
                {
                    newNode.Checked = _treeView.SelectedDirectories.Contains(path);
                }
                _treeView.MarkNode(newNode);
            }
            catch (System.ApplicationException e)
            {
                System.Diagnostics.Debug.WriteLine(e.Message, _treeView.Name);
            }
            finally
            {
                _treeView.SuppressCheckEvent(false);
            }
            //

            if (addDummyNode)
            {
                // add dummy node, otherwise there is no + sign
                newNode.AddDummyNode();
            }
            //
            return(newNode);
        }