Click to See Complete Forum and Search --> : Index of last Item added to a Combo Box


forty7
July 30th, 2001, 06:20 PM
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

John G Duffy
July 30th, 2001, 07:44 PM
Combo1.ListCount - 1

John G

Tower
July 30th, 2001, 08:14 PM
Sorry, but this is work only if List unsorted :((

forty7
August 2nd, 2001, 12:23 PM
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

RTheis
August 2nd, 2001, 12:46 PM
Is this in reference to the adding to a bound ConboBox question?