[2005] ComboBox Cancel Selection
Hi All, I want to set my combobox in such a way that it could automatically recall to its previous "item". Pls see scenario below:
1. combobox lists:
- List1
- List2
2. Original combo1.text="List1"
3. If I selected "List2" then if there is a certain event that won't satisfy and it needs to back to "List1".
looks like this...
Code:
private sub combo1_selectedindex... - selected "List2"
if not satisfied then
combo1.text=previous list or "List1"
end if
end sub
How to make it back to "List1" programatically?
Thx...
Re: [2005] ComboBox Cancel Selection
How about saving the current selection in a variable and then just comparing that to your condition. If it matches, you can set the ComboBox to whatever you like.
vb.net Code:
Public Class Form1
Private _item As String = Nothing
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
_item = Me.ComboBox1.SelectedItem.ToString()
If _item = "Item I Don't Want" Then
Me.ComboBox1.SelectedItem = "Item I Want"
End If
End Sub
End Class
Re: [2005] ComboBox Cancel Selection
Hi Nmadd, Thx for your rply. I did that before and it really works. I want something like we don't need to declare a variable. Just like in closing a form by clicking the "X" but this one has an option like:
Code:
If not satisfied then
Cancel=True
else
End
end if
I need the coding like above. Is there any possible way?
Thx...
Re: [2005] ComboBox Cancel Selection
No... there is no such way.