Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Menus
 

Menus

I want to disable and enable my application menus.  I know that if my menu caption or text is called 'Create Invoice' and the name is mnuCreateInvoice, I can do this in C# (this.mnuCreateInvoice.Enabled = false) to disable it.

Now, asuming the name is in a variable, i.e., ci = mnuCreateInvoice, what can I do to disable the menu now?  ci.Enabled = false does not work.  What should I do? I need help.
Belee  Wednesday, August 17, 2005 11:06 AM
Your question is not making any sense. The actual name of the variable has absolutely nothing to do with the caption. All objects in C# are a reference, unless they aren't therefore if ci is set to mnuCreateInvoice and ci.Enabled = false is not working then that means something is going on. Several of the things that could possibly happen are:

#1 - either ci is null - and your "not working" really means to say throwing a NullreferenceException
#2 - ci is not being set to mnuCreateInvoice but is being set to something else
#3 - the code ci.Enabled = false is not actually being called


MarcD  Wednesday, August 17, 2005 12:08 PM
Sorry! The thing is, I have a table in MS SQL server 2000 having the following columns, UserID, MenuID, MenuName, MenuCaption.

Now what I want to do is, if I retrieve the user I want to process the menus that have to be enabled for him or her.  By default all the menu items are disabled.  So when I retrieve the user and his or her menus, I now put the menu name in the sql table in a variable.  The following is the sample code:

string menuToShow;

try

{

this.dsUserInfo.UserMenusView.Clear();

this.dsUserInfo.UserMenusView.BeginLoadData();

this.cmdSEUM.Parameters["@UserID"].Value = this.userID;

this.daGetUserMenu.Fill(this.dsUserInfo, "UserMenusView");

this.dsUserInfo.UserMenusView.EndLoadData();

if (this.dsUserInfo.UserMenusView.Rows.Count > 0)

{

foreach(DataRow urow in this.dsUserInfo.UserMenusView.Rows)

{

menuToShow = (string)urow["MenuName"];
***menuToShow.Enabled = true
}

but the code with the asterix (the *** is not part of the code, just to show the line) generates this error "string does not contain a definition for Enabled"

Beleebe  Wednesday, August 17, 2005 12:40 PM
That is because menuToShow is a String not a MenuItem.

You have to now go through each menu item in your Menu and find an item who's name matches that string and then enable THAT Control
MarcD  Wednesday, August 17, 2005 8:47 PM

You can use google to search for other answers

Custom Search

More Threads

• design time bug?
• Implementation of Scroll in DataGrid using Mouse Roller Ball
• cant open the project in VS due to user control error at design time
• passing additional information to the Custom CollectionEditor
• fancy code generation
• Whidbey Designer
• DataGridView strange problem
• Reg: Custom Drawing the Menu in Dotnet 2.0
• Invoking VB6 from Smart client applications using Composit UI application Block
• Mmicrosoft Outlook Integration with VB.NET Code