Problem with Combobox in VB

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Shailja
    New Member
    • Feb 2007
    • 123

    Problem with Combobox in VB

    I have added combobox on my form. How to check at runtime that whether user has selected an item from the combobox or not? Please tell me code for that.

    I.e. I have added 3 items to combobox on form load event. When i click on Save button i want to check whether user has made selection from combobox or not. What property do i need to write for that?
  • hariharanmca
    Top Contributor
    • Dec 2006
    • 1977

    #2
    Originally posted by Shailja
    I have added combobox on my form. How to check at runtime that whether user has selected an item from the combobox or not? Please tell me code for that.

    I.e. I have added 3 items to combobox on form load event. When i click on Save button i want to check whether user has made selection from combobox or not. What property do i need to write for that?

    Code:
    if cmbName.Listindex < 0 then
             ' Not Selected Code
    else
              'Selected Code
    endif
    This will solve you

    Comment

    • Esmael
      New Member
      • Feb 2007
      • 58

      #3
      Hi...

      And pls add that code to the combobox click event
      Heres the complete snippets code:

      Private Sub Combo1_Click()
      if cmbName.Listind ex < 0 then
      ' Not Selected Code
      else
      'Selected Code
      endif
      end sub


      GOodLuck...

      Comment

      • balid
        New Member
        • Feb 2007
        • 18

        #4
        Originally posted by Shailja
        I have added combobox on my form. How to check at runtime that whether user has selected an item from the combobox or not? Please tell me code for that.

        I.e. I have added 3 items to combobox on form load event. When i click on Save button i want to check whether user has made selection from combobox or not. What property do i need to write for that?
        Since you want the check to occur when the user has clicked on the Save button put the combobox selection check in the button click event.

        Code:
         
        Private Sub save_button_Click()
           if combobox1.Listindex < 0 then
              ' Not Selected Code
           else
              'Selected Code
           endif
        end sub

        Comment

        Working...