Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How do I manage the checkonClick/uncheck on a menu item?

Posted on 2006-07-20
11
Medium Priority
?
1,239 Views
Last Modified: 2013-12-03
I have a View menu item that offiers Large Icon, Details.....  views.  I would like to have the menu item have a checked sign when selected by a user and then remove the check sign when user selects a different view option.  Thank you.
0
Comment
Question by:lapucca
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
11 Comments
 
LVL 3

Expert Comment

by:BBK_
ID: 17151797
1)      Add a ContextMenu to the Form
2)      Define 4 List view types as 4 MenuItem
3)      Assign the ContectMeny Property of List view as the newly inserted Contextmenu
4)      Now on the Popup() event of context menu Check the “View” of list view .
5)      Using a Switch – case statement like
switch (listView1.View)
{
case View.LargeIcon : contextMenu1.MenuItems[0].Checked = true; break;
......Write 4 types here
}            
0
 

Author Comment

by:lapucca
ID: 17156157
There is a CheckOnClick property for the menu item that I turn on already.  It does have a check sign when I click on those item but  it doesn't un-check when I click on another item.   This is the problem that I need help with.  Thank you.
0
 
LVL 1

Expert Comment

by:flashaoy
ID: 17159560
Tried It out and worked fine.

private void m_SortItem_Click(object sender, EventArgs e)
{
//Clearing check marks from all menu items
foreach (ToolStripMenuItem item in sortToolBtn.DropDownItems)
{
item.Checked = false;
}

//Selected the current item which is clicked.
m_SortItem.Checked = true;
}
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:lapucca
ID: 17163959
I'm not sure where is this event?  I don't see anything like it on the menustrip control's events.  Where should I add thdcode?  Thanks.
0
 

Author Comment

by:lapucca
ID: 17164914
I think I should put this at        
private void viewToolStripMenuItem_Click(object sender, EventArgs e)

but, what is "sortToolBtn.DropDownItems"??

I need to do it for each of the View option item, Large Icon, Small Icon, List and Detail.

Thanks.
0
 
LVL 3

Expert Comment

by:BBK_
ID: 17165374
lapucca, I have worked out some thing for you.



            //On Popup of the Contextmenu
            private void contextMenu1_Popup(object sender, System.EventArgs e)
            {
                  Large.Checked = false;
                  List.Checked = false;
                  Details.Checked = false;      
                  Small.Checked = false;      
                  switch(listView1.View)
                  {
            case View.Details : {Details.Checked = true; break;}
            case View.LargeIcon:{Large.Checked = false; break;}
            case View.SmallIcon:{Small.Checked = true; break;}
            case View.List:      {List.Checked = true; break;}

                  }
            }

//This is the Click of menuItem
//To take this select the item and take the event list, Click on the "Click" event.
//Take each next menuitem and select the same event hadler from the dropdown

private void menuItem_Click(object sender, System.EventArgs e)
{
      Large.Checked = false;
      List.Checked = false;
      Details.Checked = false;      
      Small.Checked = false;
      ((MenuItem)sender).Checked = true;
      switch(((MenuItem)sender).Text)
      {
            case "Large": {listView1.View = View.LargeIcon; break;}
            case "List": {listView1.View = View.List; break;}
            case "Report": {listView1.View = View.Details; break;}
            case "Details": {listView1.View = View.SmallIcon; break;}
                  }
            }
0
 

Author Comment

by:lapucca
ID: 17165476
Hi BBK,

This is the main menu strip in my main form.  It's not a popup contextmenu.  Thank you.
0
 
LVL 3

Accepted Solution

by:
BBK_ earned 2000 total points
ID: 17165559
Still the idea is same..

But if it is a main menu, then instead of assigning the Check at POPUP, you can take care it in program, like when the application starts the View Style will be LIST. So at that time make the List as checked, then the second part will take care...
I.e

private void menuItem_Click(object sender, System.EventArgs e)
{
     Large.Checked = false;
     List.Checked = false;
     Details.Checked = false;    
     Small.Checked = false;
     ((MenuItem)sender).Checked = true;
     switch(((MenuItem)sender).Text)
     {
          case "Large": {listView1.View = View.LargeIcon; break;}
          case "List": {listView1.View = View.List; break;}
          case "Report": {listView1.View = View.Details; break;}
          case "Details": {listView1.View = View.SmallIcon; break;}
               }
          }
0
 

Author Comment

by:lapucca
ID: 17170165
I still can get this to work becuase I don't know the exact property to use for the ToolStripMenu under the Menu strip.  The following is what I got but I am getting a casting error and I can't find the "checked" option.   Thanks.

        private void largeIconToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (ToolStripDropDownItem mi in viewToolStripMenuItem.DropDownItems)
                mi.DropDown = false;
            NodeDetail.Items["Large Icon"].Checked = true;
            NodeDetail.View = View.LargeIcon;
        }
0
 
LVL 3

Expert Comment

by:BBK_
ID: 17173543
I assume you are using NET Framework version 2.0.
Please refer the following link
http://msdn2.microsoft.com/en-us/library/system.windows.forms.toolstripdropdownitem.aspx
0
 

Author Comment

by:lapucca
ID: 17173590
Yes, I am using vs2005, .net 2.0.  I looked at the link you provided but I don't see what I'm looking for.  The largeIconToolStripMenuItem is the drop down menu from my mainmenu(menustrip).  I need to something like mi.checked to set it to false but I don't see it in the example you gave me.  Thank you.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question