Solved

How to detect the dropdown list value has changed?

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
Modal Popup Extender control 1 53
VB.net capture  result of a SQL query in variables 3 32
How to repeat the data 4 30
Need help with a query 14 39
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

733 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