Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / March 2006

Tip: Looking for answers? Try searching our database.

ToolStripMenuItem.CheckOnClick Does Not Fire

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
rob - 01 Mar 2006 20:55 GMT
I have a menu item that has a check mark. When ever the check mark is
toggled I do a bunch of changes in the appropriate event handler. Now
when the app starts I read the last settings and set the menu
accordingly. So in my MainFrame_Load function I call:

showItToolStripMenuItem.Checked = lastShowItStatus;

Unfortunately, setting the checked state programmatically does not
trigger my event hander. Therefore, the internal state of the program
does not match the state shown in the menu. What is the best approach
to make the event handler execute when I set the checked state?

Thanks
SnarfBlam@gmail.com - 01 Mar 2006 22:13 GMT
You have a number of options. You can explicitly invoke the event
handler. You can extract the code from the handler into a separate
method that both the click event and the constructor call. You can
duplicate the code in the constructor.

If you have the CheckOnClick property set to true, your best bet would
be to handle the CheckChanged event and ignore the Click event
altogether, since CheckChanged is raised regardless of whether the
Checked property was changed by a user or through code.
rob - 02 Mar 2006 06:00 GMT
I was thinking about extracting the code in a separate function as well
as calling the event handler directly but did not like either of it. I
did not think about CheckOnClick though. I tried it and it works great.
Thanks a lot for that advice.

On more question regarding the event handler. First of all my feeling
is that calling an event handler is a bad thing to do. If it is not
what exactly are the parameters to pass in. Sender I guess would be the
actual menu item in question. What about the arguments?

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.