Reputation: 357
I am writing an installer for an application. As part of that I am required to get the country name the user selects. If the user selects United States, I want the value US in my program, i.e. 2 letter code.
Currently I implemented the combo box like this:
<Control Id="CountryList" Type="ComboBox" Sorted="yes" ComboList="yes" Property="COUNTRY" X="30" Y="118" Width="150" Height="15">
<ComboBox Property="COUNTRY">
<ListItem Value="United States" />
<ListItem Value="India" />
<ListItem Value="Australia" />
<ListItem Value="United Kingdom" />
</ComboBox>
</Control>
Can anyone please suggest me how to change the property COUNTRY
to US
or IN
or UK
etc. I mean 2 letter code.
Also I have to add all possible countries. Any better way to accomplish this?
Related to this, I want the first combobox to list all the countries. The second combobox can then show the states that belong to the country. :)
Upvotes: 2
Views: 1833
Reputation: 32240
Use the Text
attribute for a visible text, and Value
attribute for the value to be put into the ComboBox
property when the item is selected:
<Control Id="CountryList" Type="ComboBox" Sorted="yes" ComboList="yes" Property="COUNTRY" X="30" Y="118" Width="150" Height="15">
<ComboBox Property="COUNTRY">
<ListItem Text="United States" Value="US" />
<ListItem Text="United Kingdom" Value="UK" />
...
</ComboBox>
</Control>
As for your other questions:
Also I have to add all possible countries. Any better way to accomplish this?
You can take inspiration from this thread and add a build-time step to generate an XML fragment of <ListItem>
elements.
The second combobox can then show the states that belong to the country.
Note that there's no way to catch the event when a selected item is changed in a combobox. That's a well-known limitation of the MSI UI. You can try to achieve what you want with the workaround I call "twin-dialogs". See this thread for more information.
Upvotes: 3