We help IT Professionals succeed at work.

VB.NET ComboBox Get Value before and after change

CipherIS
CipherIS asked
on
I need to get the value of a combobox when the user is selecting a new value.  I want the original value and what it was changed to.

I've been researching but have not found a solution.

Any ideas?
Comment
Watch Question

Software Team Lead
Commented:
try this:

declare the variable at class level:

Dim PrevValue As String

Open in new window


then in your Combo box's SelectedIndexChanged event:

Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
        If PrevValue Is Nothing Then
            MessageBox.Show("Previous Value: " + ", Current Value: " + DirectCast(sender, ComboBox).SelectedItem)
        Else
            If DirectCast(sender, ComboBox).SelectedItem <> PrevValue Then
                MessageBox.Show("Previous Value: " + PrevValue + ", Current Value: " + DirectCast(sender, ComboBox).SelectedItem)
            End If
        End If
        PrevValue = DirectCast(sender, ComboBox).SelectedItem
    End Sub

Open in new window

Author

Commented:
Thanks