Solved

What is the easiest way to dynamically disable events for a Control in VB.NET?

Posted on 2012-03-18
3
278 Views
Last Modified: 2012-03-20
I need to disable events for a control in order to avoid recursion. What is the easiest way to dynamically disable events for a control (or other class with events) in VB.NET?

I'm familiar with the AddHandler and RemoveHandler implementation, but I was hoping for something a little less cumbersome. Something like the Application.EnableEvents method of VBA.

Any suggestions?
0
Comment
Question by:andreas_rafn
3 Comments
 
LVL 53

Accepted Solution

by:
Dhaest earned 400 total points
Comment Utility
I would suggest setting a boolean variable to false before your operation and resetting it after. Test this variable in the the event handler and only do something if it is true.
0
 
LVL 69

Assisted Solution

by:Éric Moreau
Éric Moreau earned 100 total points
Comment Utility
I also use the suggestion from Dhaest. For example, I have a IsLoading property/variable and in some methods I have this kind of code

private sub X()
   If IsLoading then Return
   IsLoading = True
   Try
       ...
   Finally
      IsLoading = False
   End Try
end sub
0
 

Author Closing Comment

by:andreas_rafn
Comment Utility
I guess thats a effortless, but effective way of doing it :) I must admit however that I had hoped for something like Form.DisableEvents = True to exist in .NET.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now