Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2012-03-18
3
Medium Priority
?
302 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
[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
3 Comments
 
LVL 53

Accepted Solution

by:
Dhaest earned 1600 total points
ID: 37736545
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 70

Assisted Solution

by:Éric Moreau
Éric Moreau earned 400 total points
ID: 37737479
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
ID: 37744165
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

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Suggested Courses

618 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