How to pre-select a ComboBox row

[quote=111162:@Richard Duke]I encounter problem with the combo box in the process of moving to Cocoa.

When i click on the down arrow the first time, i can see the drop down value is the same as the text area.

When i click on the down arrow the second time, i can see the drop down value is not selected at all.

[/quote]

[quote=111185:@Richard Duke]Micheal, you can certainly can select a row in the drop down menu by simply setting the listIndex of the combo box.


SUB DoSetComboValue(cboRec AS comboBox, vField AS STRING)
  DIM i AS Integer
  cboRec.text=vField
  If Len(vField )<>0 Then
    For i = 0 To cboRec.listCount-1
      If cboRec.rowtag( i ) = vField  Then
        cboRec.listIndex=i
        Exit
      END IF
    Next
  Else
    cboRec.text=""
    cborec.ListIndex=-1
  END IF
  END SUB
  
[/code][/quote]

I am starting a new thread so this will be easier for future reference. It is important for people who search afterwards so they find answers more logically than looking deep down in an unrelated topic.

Setting the ListIndex in the MouseDown event works but for some reason, immediately after the selection disappear.

Use a timer to keep the ComboBox drop down menu item selected :

[code]Sub Action()
  For i as integer = 0 To ComboBox1.listCount-1
    If instr(ComboBox1.text,ComboBox1.list( i )) > 0  Then
      ComboBox1.listIndex=i
      Exit
    END IF
  next
End Sub

This seems to be a bug. The NSComboBox docs show that if there is a row matching the current text, the row is highlighted on a dropdown:

NSComboBox Class Reference

[quote=111254:@Eli Ott]This seems to be a bug. The NSComboBox docs show that if there is a row matching the current text, the row is highlighted on a dropdown:

NSComboBox Class Reference[/quote]

It is indeed a bug, I think. But as often, pending resolution, a workaround is better than nothing…

micheal… it work!!! but a pain to do that on each combo…

Create a ComboBox subclass and put the code in there.

the timer in combo box subclass??

i already using subclass for my combo box…

Has a bug report been filed in feedback?

Anyone see this?

Create a ComboBox, put 3 items inside as:

aaa
bbb
ccc

Run. Click the disclose triangle and see the items. Now quit the app (App Menu->Quit). Crash!

I see this on OS X, Xojo 2013.4.1

You cannot add a timer directly to a ComboBox subclass. But you can use a Container Control as master class, into which you place the ComboBox and the timer.

[quote=111276:@Rick Araujo]Anyone see this?

Create a ComboBox, put 3 items inside as:

aaa
bbb
ccc

Run. Click the disclose triangle and see the items. Now quit the app (App Menu->Quit). Crash!

I see this on OS X, Xojo 2013.4.1[/quote]

Still crashes in 2014R2. Bug.

Actually, you can. Add one as a property and use AddHandler to catch the action event.

OK. Did not realize a property could be a class. Thanks.

greg, any code to show me how to add handler??

Add a “Timer” as a property in the ComboBox subclass. Then AddHandler for the Action event of the timer.

[quote=111259:@Richard Duke]micheal… it work!!! but a pain to do that on each combo…
[/quote]

Put your ComboBoxes in a control set and address them all in the same timer on the page. Here I have three ComboBox named “MyCombobox()” :

Sub Action() For themember as integer = 0 To 2 For i as integer = 0 To MyComboBox(themember).listCount-1 If instr(MyComboBox(themember).text,MyComboBox(themember).list( i )) > 0 Then MyComboBox(themember).listIndex=i Exit END IF next next End Sub

[quote=111432:@Syed Hassan]For i as integer = 0 To ComboBox1.listCount-1
If instr(ComboBox1.text,ComboBox1.list( i )) > 0 Then
ComboBox1.listIndex=i
Exit
END IF
next[/quote]

thanks Syed and Greg… got it working now… using the timer and addhandler.

:frowning:

thanks micheal too…HAHAH!!!