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
181 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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

862 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

28 Experts available now in Live!

Get 1:1 Help Now