How to set a default select for a combo box?

How to set a default select for a combo box?

I have created a combo box for a list of values. Now I need to set a selection, so a value will already be selected when presented to the user.  But seems from the combo box settings, there's nowhere I can set the value from the source record list.
The OutSystems way of doing it is by setting the associated variable. Each combobox is connected to one variable so assign the variable with the value you want. The user can see it and change it in the combobox.

It is also useful if you have OnChange Events on other fields that cause changes to the Record list that feeds that combobox. Just assign a new value to the variable and the combobox goes along (just don't forget to Refresh the combobox to load the new record list).
Thanks.  What I want is to have an option from the option list pre-seleted.  For example, if the Color combo box has 4 options, 0 (none slection), red, green and blue in this order, I want to have a color, say blue, selected when the combo box is displayed on the page.  If I want to show a page for editing a record and the original value for the Color attribute is blue, I certainly want to have blue already picked in the Color combo box when presenting the record for editing.  Currently (at least it appears to me) the combo box always has the first option picked.  One workaround I can think of is to put the origianl color as the first option, but it's not desirable to change the order of the options.
Hi Zhang,

If you're using properties "Source Record List" / "Source Entity/Structure" for getting the items, you'll have to set the Variable property. Like Nuno was saying, you have to ensure, in the preparation, that this variable has the desired value.

If you're using the "Special List" (value 1, option 1, etc), the same applies to the Special Variable property.

See also this: Use Combo Boxes to Select From a List

I guess I didn't make myself clear.  Say you have a page for editing a record.  On the page there's a combo box for controlled input values, say red, green, blue, plus 0 as value 1 for the special list for non-slection. When you come to this page to edit a record, the combo box is presented with non-selection selected.  But the record you're editing has blue as the value for the combo box attribute.  So you surely like to have blue already selected for you when you come to the edit page so you don't need to do anything to the combo box if you want to keep its original value (and you can see the original value is blue for the record).  When you come to an edit page for a record, you surely like the original values of the record being filled in so you only need to do something to those fields you want to make changes.  But now in the case of combo box, always the first opiton is selected so you have to re-select blue if you want to keep its oritinal value.  What's needed here is a default value which you can set to point to a local variable which in turn you assign a value in preparation. Then if the local variable contains the value that matches one of the options in the combo box, that option will be selected on the edit page for that combo box. If no matches or the default value's not set, the first option will be selected, just like the way it is now. 
You may be having a problem passing the Id to your edit screen, loading the data in the preparation, or binding the data to your combobox...  can you narrow this for us? Posting the eSpace as an attachement will surely help.
Thanks Paulo.

When you go to an edit page, you surely have the info needed to retrieve the record to be edited. Let's take a look at the online training vedio 5.3. Starting at 5:40, you see a record being edited. All the fields are filled in with its original values, including the combo box for category which is empty because the record has no value for this field.  But after a category is assigned (Electronics in this case),  when you come to this edit page again, you surely like to see Electronics being seleted already for the category combo box (actually this should be the correct way), that is, when you come to edit this record again, the page would(should) look like the one at 5:50. You can surely find out what's the original value for this combo box of this record you're editing.

In the case of the example in the video, the html source code for the combo box of the edit page should look like something as this:

<option value="1">Books</option>
<option value="2" selected>Electronics</option>
<option value="3">Movies</option>
<option value="4">Sports</option>
Hi Zhang,

We understood what the correct behavior should be - we were trying to help you on the specific issue you were facing.

For understanding how to achieve this behavior, please see Nuno's and my answer above. I also strongly suggest you to see all the videos in the academy. Again, if you're facing a particular issue with this pattern, please provide your eSpace / more details so we can help you.
Thanks Paulo.

What I posted on this subject is to explain what I have been looking for.

I've been watching the videos and trying to see an example that may apply to my case. In the video 8.3 at time 6:38, it shows the combo box has the original value selected and I have duplicated it. But seems it only works for combo box linked to a static entity.  I'm wondering what would happen if you tried to edit a product which already has a category assigned as in video 5.3. For example, after you have assigned Electronics to the product Dell 23" screen's category as shown at time 5:42, you click the Dell 23" screen link again at 5:44, will Electronics show in the combo box?  If yes, I like to know how to achieve that.  I have a similar situation and have been trying to get the previous selected value to show in the combo box when the edit page is visited again after the previous edit, but so far with no success.

See attached a small sample with a pattern similar to the one in the video.

The key combobox property here is Variable. It can be a local screen variable, a session variable... In the Product_Edit screen, it's set as ProductEdit.Record.Product.ColorId - meaning that it's taking its default value from the ProductEdit Edit Record widget. This will also keep the modified value, in case the user edits an item.

ProductEdit itself is using GetProductById.List.Current as its Source Record - which is a query in the Preparation (loading the data just before the screen is rendered).

GetProductById just loads the product specified by the screen input parameter (ProductId) - which is supplied when navigating from screen Product_Show.
Thanks Paulo.

Now I'm able to get the original value shown in the combo box based on your info. But now I have problem to save the record. Seems the record didn't get updated with the selected value (actually an empty record got sumbitted).

I can't open your sample file because my service studio is version 7.0. Can you post the sample file for this version?
Zhang, you probably used a new variable to define the combobox value.
You can only link one component to one variable. If you said "Combobox gets its value from Variable", you can't also say "Comboboxbox sets Record".

Instead of assining the original value to a new variable, assign to the destination record field. That way, the "Record sets the original value" AND "the Combobox sets the Record".
Thanks all for your help.

I've resolved the issue.  Actually I figured out what Nuno said based on what Paulo said, that is, in the preparation, I just assigned the retrieved record (query.List.Current.<entity>) to editcontainer.Record.<entity>. 

I have another chalenge though which I'll post in a new thread, if I can't figure it out.