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
182 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
ID: 24034559
You can use a boolean variable to indicate that you have done from code
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 24034575
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
ID: 24034579
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
ID: 24034598
>> 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
ID: 31565094
Cheers mate
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

806 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