Solved

Any way to tell if an event was fired by user as opposed to via a code update?

Posted on 2009-03-31
5
180 Views
Last Modified: 2012-05-06
I suspect i already know the answer to this - but the question is pretty simple.

If i have a combobox, and i change the items in code using syntax like
cmbWhatever.SelectedIndex = 5

It fires the SelectedIndexChanged event. The question is, inside that event handler, is there any way to establish whether the event was fired from code (like the example above) or whether it was fired as a result of a user action?
0
Comment
Question by:tfsln
  • 3
  • 2
5 Comments
 
LVL 48

Expert Comment

by:jpaulino
Comment Utility
You can use a boolean variable to indicate that you have done from code
0
 
LVL 48

Expert Comment

by:jpaulino
Comment Utility
Something like
    Private codeSelection As Boolean = False
 

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        codeSelection = True

        Me.ComboBox1.SelectedIndex = 5

        codeSelection = False

    End Sub
 

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
 

        If codeSelection Then

            Debug.WriteLine("code selection")

        Else

            Debug.WriteLine("user selection")

        End If

    End Sub

Open in new window

0
 

Author Comment

by:tfsln
Comment Utility
Yeah thats the way i currently do it... I wanted to check and make sure there wasn't a tidier way.

So basically, the answer to my question is no?
0
 
LVL 48

Accepted Solution

by:
jpaulino earned 500 total points
Comment Utility
>> So basically, the answer to my question is no?
Yes, it's no. I don't think you have other option.
0
 

Author Closing Comment

by:tfsln
Comment Utility
Cheers mate
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

763 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

7 Experts available now in Live!

Get 1:1 Help Now