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
184 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
[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
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

730 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