Results 1 to 4 of 4

Thread: [2005] ComboBox Cancel Selection

  1. #1

    Thread Starter
    Member
    Join Date
    May 2008
    Posts
    59

    [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...

  2. #2
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    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:
    1. Public Class Form1
    2.     Private _item As String = Nothing
    3.  
    4.     Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
    5.         _item = Me.ComboBox1.SelectedItem.ToString()
    6.  
    7.         If _item = "Item I Don't Want" Then
    8.             Me.ComboBox1.SelectedItem = "Item I Want"
    9.         End If
    10.     End Sub
    11. End Class

  3. #3

    Thread Starter
    Member
    Join Date
    May 2008
    Posts
    59

    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...

  4. #4

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width