A Little help with Combo Boxes?

I can select an item from the box and everything works, but when I reload DX Builder the box displays the 1st item on the list instead of my last selection. The item IS selected and the results are correct but the display doesn't show the correct item.

Does anyone know how to make the combo box keep your last selection on display? Thanks.
3,288 views 3 replies
Reply #1 Top
Could you maybe set that when the OnSelect event is fired, you save the Control.Text to a persistent DX variable.

Then in the OnScriptEnter event, load the Control.Text from that variable.

That way the combo box will retain the 'text' of the control between loads.
Reply #2 Top
I could not get my test combobox to remember the selected item, nor display it. That may depend on other factors, such as how the items are added to the list, I did not test.

If your box is indeed remembering the last selected Item, just not displaying it, maybe a line like:

Control.ListIndex = Control.ListIndex

In the OnScriptEnter would straighten out the display (and trigger an OnSelect event too).

But I think Skarnivorous is on the right track. Store the selection information in some manner, and use that when initializing the box. Or perhaps the proper list item to display can be determined in some other way--for example, if your box lists a selection of "sizes" to make another object, you could check the "size" of the other object to know which list item should be currently displayed.
Reply #3 Top
Hey thanks, you guys! I combined your suggestions and it worked.

Here's an example script:

Dim items
items= Array("item1","item2","item3")

Sub object_OnScriptEnter
control.listindex = object.PersistStorage("lastselected")
End Sub

For x = 0 To 2
control.AddItem items(x)
Next

Sub Control_OnSelect(Item, string)
object.PersistStorage("lastselected")= item
End Sub



Of course, it kept giving me an error everytime I tried to apply the script (because persiststorage was empty) but when I closed the error message, made a selection in the combo box, and then restarted DX everything worked fine. Thanks again, you're both going on the special thanks list for this project!