How is the Combo Box value for each entry assigned?

I want to use a combo box with several entries. But I do not understand how the Control.value is assigned. The value for each entry also changes when I choose "sort alphabetical" yes or no.

Which logic is there behind?
How to be sure that with language overlay the matching entries have the same value?

With Control.value.name I could get the "real name" of each entry, but that does not work when I use language overlays.

I want to define based on the choosen entry different values for a variable.
E.g.
if "skip the file" is choosen the variable x shall be "skip"
if "ask for each file" is choosen the variable x shall be "ask"

So I assume I would need to use the value and not value.name. Or what is there the best approach?

I could not find a similar question in the forum. Only how to get the value and value.name.

Control.value returns a DialogListItem object, which has a data property you can use to store arbitrary data with the object.

I do not understand what you mean. I found the mentioned commands in the manual, but also the description there I do not really understand (how it would help in my case).
There is written the dialoglistitem is returned by Control.GetItemAt.

I created a combo box with the dialog editor and added several entries.
The assumption was that there is a return value based on the entry which is chosen.
Is that wrong?

Each item in a combo has three pieces of information associated with it:

  • index - its order in the list of items (0, 1, 2, 3, 4, ...)
  • name - the text showin in the control
  • data - an arbitrary data value

The DialogListItem object has properties that expose this information. So when you call Control.value to get the selected item, you can use Control.value.data to access that item's data value. You can use that data value for anything.

Ah, now it gets more clear. Thank you.
So the Control.value from a combobox is more like a matrix and contains several information?!
Based on this example I thought value and value.index are identical.

Index and name is clear. I guess data has to be set via script by myself and contains nothing out of the box?
I will check this out in the evening.

It seems value and value.index are identical. But I think I understand now the pattern:
the first entry gets the value 0, the second 1, ...
No idea where the problem was yesterday evening :smiley:

If you choose alphabetical the value is assigned accordingly new. If you want to work with value or index this setting should not be changed afterwards...

If the items aren't sorted then you can use the indexes to identify them.

If they're sorted, then they'll be in a different order for each language. The easiest way to deal with that situation would be to not add the items to the combo in the dialog editor, and instead have standalone strings for them. Then add the strings + identifiers (via the data property) to the combo in your script code when the dialog opens. That gives you the ability to add a string to the combo and give it an ID (data) which can be used to recognise it.

We may also add a way to define data values for combo items in the dialog editor, to make this easier in the future, but it's not currently possible. (Although Jon mentioned it can be done by editing the XML directly instead of using the UI. But I think adding the items to the combo in your code would be preferable to that, as it would be less fragile when editing.)

Thank you. That works. I use this code:

lg.window = tab;
Dlg.icon = "question";
Dlg.top = true;
Dlg.template = "destination";
Dlg.detach = true;
Dlg.Create();
Dlg.Control("combo1").AddItem(DOpus.Strings.Get("ask"), 1);
Dlg.Control("combo1").AddItem(DOpus.Strings.Get("skip"), 2);
Dlg.Control("combo1").AddItem(DOpus.Strings.Get("replace"), 3);
Dlg.Control("combo1").AddItem(DOpus.Strings.Get("rename"), 4);
Dlg.Control("combo1").AddItem(DOpus.Strings.Get("renameold"), 5);
Dlg.Control("combo1").AddItem(DOpus.Strings.Get("keepnewer"), 6);		
Dlg.Control("combo1").SelectItem(0); // Default entry when dialog opens. Value is -1 compared to above defined data values
var retVal = Dlg.RunDlg();

In the ressources is then the definition for each language (excerpt).

	<resource type="strings">
       	<strings lang="francais">
           	<string id="ask" text="Demander quoi faire" />
			<string id="skip" text="Ignorer le fichier" />
             ...
       	</strings>
       	<strings lang="deutsch">
           	<string id="ask" text="Nachfragen was getan werden soll" />
			<string id="skip" text="Datei ├╝berspringen" />
             ...
       	</strings>
       	<strings lang="english">
           	<string id="ask" text="Ask what to do" />
			<string id="skip" text="Skip the file" />
             ...
       		</strings>
    </resource>
1 Like