Solved

How to detect the dropdown list value has changed?

Posted on 2004-10-06
5
924 Views
Last Modified: 2008-04-04
Hi,
I have a dropdown box in windows form application. Dropdown style is 'dropdown list'.

When the selection in the dropdown is changed I want to find out if the newly selected value is different from the old value or the user has selected the old value again.

The events 'SelectedValueChanged' and 'SelectedIndexChanged' are fired even when the old value is re-selected. I do not want to trigger the event if the old value is chosen again. Is there any event that can detect whether the user is re-selecting same value that is currently selected? If there is no event to handle this, is there any simpe coding that will detect this?

Thanks in advance.

0
Comment
Question by:Coolcld
  • 2
  • 2
5 Comments
 
LVL 19

Accepted Solution

by:
Desp earned 125 total points
ID: 12236790
use a private class level variable

dim CurrentIndex as Int32

intitalize this to -1 in the beginning (FormLoad)
CurrentIndex = -1

in the SelectedIndexChanged event you can put this code:
if cmbTerritory.SelectedIndex =CurrentIndex then
           msgbox ("Previously selected")
else
           msgbox ("Previously selected")
           CurrentIndex  = cmbTerritory.SelectedIndex
Endif
       
   

0
 
LVL 25

Assisted Solution

by:RonaldBiemans
RonaldBiemans earned 125 total points
ID: 12236806
There is no event to check that, but if you declare a variable that hold the currentvalue you can check against that
something like

Dim x As Object

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        If ComboBox1.SelectedItem() = x Then
            MsgBox("same")
            Exit Sub
        Else
            x = ComboBox1.SelectedItem()
            MsgBox("changed")
        End If

    End Sub
0
 
LVL 19

Expert Comment

by:Desp
ID: 12236808
i coverted the C# syntax to VB here directly ... so it may hve error
0
 

Author Comment

by:Coolcld
ID: 12236928
Hi Desp and RonaldBiemans , Thanks for the solution.

I would like to divide the points between Desp and RonaldBiemans.
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 12236974
Then click split points, and assign the points you want
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
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 …
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…

829 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