CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2001
    Location
    CA
    Posts
    153

    Index of last Item added to a Combo Box

    I know there's a way to read the index of the last item added to a combo box. Does anyone remember?

    thanx/good luck,
    adam
    thanx/good luck

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

    Re: Index of last Item added to a Combo Box

    Combo1.ListCount - 1

    John G

  3. #3
    Join Date
    May 2001
    Location
    Russia
    Posts
    200

    Re: Index of last Item added to a Combo Box

    Sorry, but this is work only if List unsorted (

    Andy Tower

  4. #4
    Join Date
    Apr 2001
    Location
    CA
    Posts
    153

    Re: Index of last Item added to a Combo Box

    Finally remembered:
    After you've added an item to a combobox, you can look at .NewIndex to see where it was added in the combo, even if the combo is sorted.

    here's some entertaining code if you want to try it out:
    this form has 5 buttons and one combo with Style = 2 and Sorted = True



    option Explicit

    private Sub Command1_Click()
    Combo1.AddItem "abc"
    Combo1.ItemData(Combo1.NewIndex) = 100
    MsgBox Combo1.NewIndex

    End Sub

    private Sub Command2_Click()
    Combo1.AddItem "def"
    Combo1.ItemData(Combo1.NewIndex) = 500
    MsgBox Combo1.NewIndex
    End Sub

    private Sub Command3_Click()
    Combo1.AddItem "xyz"
    Combo1.ItemData(Combo1.NewIndex) = 1000
    MsgBox Combo1.NewIndex
    End Sub

    private Sub Command4_Click()
    Dim intcounter as Integer
    for intcounter = 0 to Combo1.ListCount - 1
    MsgBox Combo1.ItemData(intcounter)
    next intcounter
    End Sub

    private Sub Command5_Click()
    Combo1.Clear
    End Sub




    you'll notice that by clicking button4 you'll see the correct .ItemData for each Item in the combo even if you added the data out of alphabetical order.

    thanx/good luck,
    adam
    thanx/good luck

  5. #5
    Join Date
    Aug 2001
    Location
    Houston, Texas
    Posts
    2

    Re: Index of last Item added to a Combo Box

    Is this in reference to the adding to a bound ConboBox question?


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