Search code examples
c#.netwinformstoolstripmenu

Tri State Chech box for ToolStripDropDownButton


I have statusbar strip with ToolStripMenuItems. I need to gruop the Toolstrip menu items and Implement TriStateCheckbox functionality,

  1. Is it Possible to Create checkbox with ToolStripMenitems?
  2. If its not Possible for Point 1, then How to Add TreeView to StatusStrip. enter image description here

Solution

  • To have a three-state menu item, you can set CheckState of each ToolStripMenuItem to Indeterminate, Checked or Unchecked.

    enter image description here

    Also if you want to use a tree-view control (which doesn't have builtin support for three-state check boxes) or something like this control, you should know, you can host any control in drop-down using ToolStripControlHost. For example, here is a ToolStripTreeView control:

    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Windows.Forms.Design;
    [ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.ContextMenuStrip)]
    public class ToolStripTreeView : ToolStripControlHost
    {
        [DesignerSerializationVisibility( DesignerSerializationVisibility.Content)]
        public TreeView TreeViewControl { get { return (TreeView)Control; } }
        public ToolStripTreeView() : base(CreateControl()) { }
        private static TreeView CreateControl()
        {
            var t = new TreeView();
            return t;
        }
    }
    

    enter image description here