CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2001
    Location
    israel
    Posts
    99

    Problem with ListIndex in ComboBox

    hi guys,

    i have a combo box in my application. the combo box's style is dropdown list and is sorted.
    i added items to the combo box like this:


    for Index = 1 to 10
    CustID = somestring
    cmbCustomer.AddItem CustID
    next Index




    i also added some code to the Click event.
    problem is that no matter what item i click on the ListIndex property is always -1, and i cant the item that was selceted

    any idea how to solve it?

    thanks,
    ohad.


  2. #2
    Join Date
    Apr 2001
    Location
    Wisconsin, USA
    Posts
    150

    Re: Problem with ListIndex in ComboBox

    try this:



    for intIndex = 1 to 10
    CustID = somestring
    cmbComboBox.AddItem(CustID, intIndex)
    next intIndex




    This will place your item at the specified index in the combo box.


  3. #3
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: Problem with ListIndex in ComboBox

    I tried this simple program and could not reproduce your complaint. Everytime I clicked a listItem, It produced the desired results. The COmboBox style was set to 2 - DropDownList.

    option Explicit

    private Sub Combo1_Click()
    print Combo1.ListIndex
    End Sub

    private Sub Form_Load()
    Dim I
    for I = 1 to 10
    Combo1.AddItem I
    next I

    End Sub




    John G

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