?
Solved

How to detect the dropdown list value has changed?

Posted on 2004-10-06
5
Medium Priority
?
937 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
[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
  • 2
  • 2
5 Comments
 
LVL 19

Accepted Solution

by:
Fahad Mukhtar earned 500 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 500 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:Fahad Mukhtar
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

Technology Partners: 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

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…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

752 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