Is it possible get the selected item position in a combo box without for next method?

I get the total items of a combo box by using “oComboBox.ItemCount”
I get the string of a selected item of a combo box by using “oComboBox.Text”
But How do I get the position of the selected item in a combo box?




same error mensage


Sub oComboBox_ItemStatusChanged(oEvent As Variant)
Dim nomItem As Long 
	nomItem = oEvent.Selected
	Print "Selected " & nomItem & " (" & oEvent.Source.getItems()(nomItem) & ")"
End Sub

1 Like

Sorry. It didn´t work. I want to select item by using ENTER key.
The Item Status Changed Event doesn’t even trigger.

The Key Pressed Event triggers.

I also tried to use “oEvent.Source.SelectedItemPos”, but I got an error

Maybe the solution is “For…to…next” method…but I think that there must be a simple line method.

Sub KeyPressed(oEvent as Object)
Dim oSheet as Object
Dim sItem as String
Dim iItems as Integer
Dim x as integer
Dim bFound as Boolean
Dim oCell as Object
If oEvent.KeyCode = Then
iItems = oEvent.Source.ItemCount
sItem = oEvent.Source.Text
x = 0
bFound = false
While not bFound and x < iItems
If oEvent.Source.getItem(x) = sItem Then
oSheet = ThisComponent.Sheets.getByName(“Cobranca”)
oCell = oSheet.getCellByPosition(1, x+3) 'The searched list begins 3 rows above combo box
bFound = True
x = x + 1
End if
ElseIf oEvent.KeyCode < 256 or (oEvent.KeyCode > 265 and oEvent.KeyCode<> 1024_
and oEvent.KeyCode<> 1025 and oEvent.KeyCode<> 1280 and oEvent.KeyCode<> 1283) Then
End If

End Sub

This worked quite well in my test:

Screenshot at 2021-09-27 18-15-17

Screenshot at 2021-09-27 18-15-43

Tested in both Base and Calc - both same result.

I do realize the problem stated by @Jonjozz and do not have a solution for that.

Thanks for your attention, but the code doesn’t trigger when the item is selected by ENTER key.