Question Make ContextMenuStrip Item Invisible

Dflat

New member
Joined
Jun 18, 2013
Messages
1
Programming Experience
5-10
I've created a ContextMenuStrip like this:
Item_tree.ContextMenuStrip =new ContextMenuStrip();
Item_tree.ContextMenuStrip.Items.Add("new", Images.Images[0], New_Context_Click);
Item_tree.ContextMenuStrip.Items.Add("copy", Images.Images[0], Copy_Context_Click);
Item_tree.ContextMenuStrip.Items.Add("edit", Images.Images[0], Edit_Context_Click);


What I want to do is to make certain items in the list visible only under certain conditions.
Disregarding how this decision is made, I can't figure out how to make the specific item visible or not.


Any help would be appreciated.


Thanks.
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
3,151
Location
Sydney, Australia
Programming Experience
10+
You don't make it visible or not. If you don't want the item to be displayed then you don't add it in the first place or remove it. You could either build the whole menu contents each time it's displayed or you could insert and remove that item as required.
 

JohnH

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
826
Location
Norway
Programming Experience
10+
The ToolstripItem has a Visible property for this purpose. You can look up the item from the Items collection either by index or by name, for latter you need to set the item Name property first.
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
3,151
Location
Sydney, Australia
Programming Experience
10+
The ToolstripItem has a Visible property for this purpose. You can look up the item from the Items collection either by index or by name, for latter you need to set the item Name property first.
Hmmm... it's really quite embarrassing that I didn't know that. I guess I must never once have had cause to use it. Still, no excuse.
 
Top Bottom