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

x
?
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
Medium Priority
?
190 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 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

609 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