CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2002
    Posts
    47

    Question about the combo box

    HI !

    I have some combo box in which the user cannot write. He has to pick an item in the list. How can i do that ?

    In another combo box the user can chose an existing item in the list or write something else. Is it possible for me, in my code, to know if the user select an item in the list or write something in the combo box ?

    Thanks for your help

    Alexandre
    Alexandre

  2. #2
    Join Date
    Oct 2005
    Location
    Islamabad, Pakistan
    Posts
    1,277

    Re: Question about the combo box

    Q#1
    Set dropDownStyle property to dropdownlist of combobox to allow the user to only select from dropdown list.

    Q#2
    Save the SelectedIndex when dropDown is Closed.
    Code:
        Private _itemIndex As Integer = -1
    
        Private Sub ComboBox1_DropDownClosed(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.DropDownClosed
            _itemIndex = ComboBox1.SelectedIndex
        End Sub
    When dropDown then update the selectedItem to the new Value.
    Code:
        Private Sub ComboBox1_DropDown(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.DropDown
            If _itemIndex <> -1 Then
                ComboBox1.Items(_itemIndex) = ComboBox1.Text
            End If
        End Sub

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

Featured