By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,635 Members | 2,060 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,635 IT Pros & Developers. It's quick & easy.

How to disable a menu item had its sub memu items?

P: n/a
Hi, friends,

I am using C#.net 2005 to create a windows application.

It has menu items, such as File, etc.
Under File, there are more menu items, such as New Files, Working Files, etc.
Under New Files/Working Files, there are more sub menu items, respectively.

All those menu items are enabled at beginning.

It requires that:
If a user clicks on a sub menu of New Files, New Files menu and
all its sub menu items will be disabled;
If a user clicks on a sub menu of Working Files, Working Files
menu and all its sub menu items will be disabled.

In my source code, once a user clicks on a sub menu of New Files, I set
newFilesStripMenuItem.Enabled = false;
hoping that it will disable New Files menu and all its sub menu items
without writting 10 more lines to disable each its sub menu items one by one.

To my surprise, when I moved mouse pointer from Working Files menu (which
was still enabled and automatically displayed all its sub menu items while
moving mouse pointer) to New Files menu, all sub menu items of New Files menu
was displayed!

I was expecting all those sub menu items should NOT be displayed since New
Files menu was DISABLED. (Indeed, if I put mouse pointer on New Files menu
first without moving from Working Files menu, or if I clicked on New Files
menu directly, all those sub menu items could NOT be displayed)

Any ideas? Thanks a lot.
Aug 10 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi Andrew,

I would suggest you to write your own MenuItem class which will handle items
on proper way. Here is a small example which checks always if OwnerItem is
enabled and if it is than it checks it's own state (enabled/disabled). If
OwnerItem is null than it also check it's own state, but if OwnerItem is
disabled than it is also disabled.

namespace TestMenuItem
{
//include support for designer.

[ToolStripItemDesignerAvailability(ToolStripItemDes ignerAvailability.All)]
public partial class TestMenuItem : ToolStripMenuItem
{

public TestMenuItem(): base(){}

public override bool Enabled
{
get
{
if (this.OwnerItem == null)
return CheckVisibility();
else if (this.OwnerItem.Enabled)
return CheckVisibility();
else
return false;

}
}
protected bool CheckVisibility()
{
// please here implement your logic here
}
}
}
Hope this helps.

rgds,
dlm,
www.bypsoft.com
cross-database comparison and synchronisation tools
DBTYP.NET - see differences, for free.

"Andrew" <An****@discussions.microsoft.comescribió en el mensaje
news:7E**********************************@microsof t.com...
Hi, friends,

I am using C#.net 2005 to create a windows application.

It has menu items, such as File, etc.
Under File, there are more menu items, such as New Files, Working Files,
etc.
Under New Files/Working Files, there are more sub menu items,
respectively.
>
All those menu items are enabled at beginning.

It requires that:
If a user clicks on a sub menu of New Files, New Files menu and
all its sub menu items will be disabled;
If a user clicks on a sub menu of Working Files, Working Files
menu and all its sub menu items will be disabled.

In my source code, once a user clicks on a sub menu of New Files, I set
newFilesStripMenuItem.Enabled = false;
hoping that it will disable New Files menu and all its sub menu items
without writting 10 more lines to disable each its sub menu items one by
one.
>
To my surprise, when I moved mouse pointer from Working Files menu (which
was still enabled and automatically displayed all its sub menu items while
moving mouse pointer) to New Files menu, all sub menu items of New Files
menu
was displayed!

I was expecting all those sub menu items should NOT be displayed since New
Files menu was DISABLED. (Indeed, if I put mouse pointer on New Files menu
first without moving from Working Files menu, or if I clicked on New Files
menu directly, all those sub menu items could NOT be displayed)

Any ideas? Thanks a lot.


Aug 16 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.