Setting editable value for "Simple List" combo box throws error

I'm trying to use the label property to programmatically set the editable value of a combo box. The code is very simple:

function onArtistEditChanged(msgValue) {
	// Start with an empty combo box
	controls.artistComboBox.RemoveItem(-1);

	controls.artistComboBox.label = msgValue;
}

When the combo box control is set to type "Drop-down Edit", this code works as expected: msgValue is assigned to the editable portion of the control. When the combo box type is set to "Simple List", however, the assignment line of code throws the following error:

Invalid procedure call or argument (0x800a0005)

Is the property name different for Simple Lists?

From the manual's description of the label property:

Note that for combo box controls, this property is only valid for an editable combo - that is, one that you can type your own text into.

You want the value property instead:

  • List box / combo box / list view: Returns or accepts a DialogListItem representing the selected item. When setting the value it also accepts an int representing the 0-based index of the selected item.

The Simple List is an editable control -- it has an edit box at the top. That's the value I'm trying to set.

The value property doesn't throw an error, but it also doesn't do anything; changing the code to

controls.artistComboBox.value= msgValue;

just leaves the editable portion of the combo box (in Simple List mode) unchanged. That makes sense, because value is supposed to set or get the selected item, which is not what I'm after.

Ah, my mistake. That looks like a bug in the scripting object. We'll fix that for the next beta.

Thanks, this is working for me in the latest beta. One thing though: although I can set the value in the edit box at the top of the Simple List, the edit cursor ends up at the beginning of the edit box, not at the end. Is there any way to place the cursor at the end of the edit control after setting the editable value?

I'll describe what I'm trying to do, in case you can suggest an easier way to accomplish it. I want to capture what the user types in real time and filter the contents of the list on each keystroke. To do this, I'm responding to each editchange event by doing the following:

  1. Clear the entire list box by invoking [control].RemoveItem(-1).
  2. Since Step 1 has the side effect of also clearing the edit box, I reset the contents of the edit box using the label property. This leaves the cursor at the beginning of the edit box.
  3. Iterate over the list of all possible values for the list control. For each value that starts with the string in the edit box, add that value back to the list box.

All of this works, except the user has to keep moving the cursor back to the end of the edit box on every keystroke.

You can use the Control.SelectRange() method to set the cursor position (set the range start and end position to the same value to position the cursor without a selection).

Perfect! Thanks for the solution.