[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 946
  • Last Modified:

How to detect the dropdown list value has changed?

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
Coolcld
Asked:
Coolcld
  • 2
  • 2
2 Solutions
 
Fahad MukhtarDistinguished EngineerCommented:
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
 
RonaldBiemansCommented:
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
 
Fahad MukhtarDistinguished EngineerCommented:
i coverted the C# syntax to VB here directly ... so it may hve error
0
 
CoolcldAuthor Commented:
Hi Desp and RonaldBiemans , Thanks for the solution.

I would like to divide the points between Desp and RonaldBiemans.
0
 
RonaldBiemansCommented:
Then click split points, and assign the points you want
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now