Set a default value to DVelop Combo

 

The Dvelop Combo can be loaded with a default value.

For example, if we have Countries like "Canada", "México" and "Tailandia in a DvelopCombo, and if we select "Mexico" as a country, we want to load the City "Ciudad de México" by default. For this we can follow the next steps:

First, we can define two transactions as follow:

Two GeneXus Structure editor tabs are shown side by side: the Country transaction structure with CountryId, CountryName, and a nested City level containing CityId and CityName, and the DefaultDvelopCombo transaction structure with DefaultDvelopComboId, CountryId, and CityId attributes.

 

Next, we define the attributes CountryId and CityId like DvelopCombo:

The GeneXus IDE shows the DefaultDvelopCombo transaction with the Work With Plus pattern applied, its Default list preview displaying COMBO ID, ID (Value dropdown), and ID fields with Confirm, Cancel, Delete buttons; the Properties panel on the right shows Control Info settings for a Custom DVelop Combo control, including Data Source From Attributes, Item Values Countryld, Item Descriptions CountryName, Sort Descriptions True, and Load Data Dynamically True.

 

Finally, if we already know the CityId of a specific country, in our example "México", we can set a default value to the City field "Ciudad de México".

A form shows an Id field set to 1 and a Name field with the value Mexico highlighted; below it a grid lists Id/Name rows with row 1, Ciudad de Mexico highlighted, followed by rows Cancun, Acapulco, and Monterrey.

 

In this case, we need to configure the event Combo_CountryId.OnOptionClicked, setting the values for CityId:

        &ComboCityId = 1
        Combo_CityId.SelectedValue_set = '1'
        Combo_CityId.SelectedText_set = 'Ciudad de México'

 

The GeneXus Events editor for the DefaultDvelopCombo transaction shows the Combo_CountryId.OnOptionClicked event source code, with Work With Plus pattern-generated lines setting &CondCountryId, &ComboCountryId, and clearing City combo values; a highlighted block below the generated code manually sets &ComboCityId to 1 and Combo_CityId.SelectedValue_set/SelectedText_set to '1' and 'Ciudad de Mexico'.

 

The result is this:

The Default Dvelop Combo web form displays a General Information panel with a Combo Id field set to 0 and two empty Id dropdown fields below it, plus Confirm and Cancel buttons.