Solved

How to detect the dropdown list value has changed?

Posted on 2004-10-06
5
897 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video discusses moving either the default database or any database to a new volume.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

757 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

23 Experts available now in Live!

Get 1:1 Help Now