# Conditional Dropdowns

> Conditional dropdowns enable you to select an option from the dropdown, based on a previous selection made in another form component.

Conditional dropdowns enable you to select an option from the dropdown, based on a previous selection made in another form component.

For example, if you select a specific state from a dropdown list, the conditioned dropdown displays the cities in that state.

## Tutorial

To use this feature:

1. Create a **parent** dropdown, by defining a workflow variable of type `List<String>` or `Dictionary<String, String>`. For example, `stateList`.
2. Create a **child** dropdown, by defining a workflow variable of type `Dictionary<String, List<String>>` or `Dictionary<String, Dictionary<String, String>>`. For example, `cityStateMap`.

   ![docs image](https://dev-assets.cms.uipath.com/assets/images/activities/activities-docs-image-183509-e7c79538.webp)
3. Drag and drop the [Invoke Code](https://docs.uipath.com/activities/other/latest/workflow/invoke-code) activity into the workflow sequence.
4. Click **Edit Arguments** and add the previously created variables as **In/Out** arguments. Click **OK**.

   ![docs image](https://dev-assets.cms.uipath.com/assets/images/activities/activities-docs-image-180040-2a54df9a.webp)
5. Click **Edit Code**. Enter the code to initialize the data and populate the dropdowns with data. For example, the following code snippet initializes the dropdowns (`stateList` and `cityStateMap`) and adds items to them.
   ```
   // initialize the parent dropdown
   stateList = new List<string>();
   // add items to the parent dropdown
   stateList.Add("HP");
   stateList.Add("Punjab");
   // initialize the child dropdown
   cityStateMap = new Dictionary<string,List<string>>();
   // add items to the HP-child dropdown
   cityStateMap.Add("HP",new List<string>());
   cityStateMap["HP"].Add("Shimla");
   cityStateMap["HP"].Add("Solan");
   cityStateMap["HP"].Add("Hamirpur");
   // add items to the Punjab-child dropdown
   cityStateMap.Add("Punjab", new List<string>());
   cityStateMap["Punjab"].Add("Chandigarh");
   cityStateMap["Punjab"].Add("Patiala");
   cityStateMap["Punjab"].Add("Jalandhar");
   ```
6. Drag and drop the **Create Form** activity.
7. Store the user dropdown selection into workflow variables. For example:
   * `cityListSelected`, of type `List<String>`—stores the list corresponding to the selected state.
   * `selectedState`, of type `String`—stores the selected state.
   * `selectedCity`, of type `String`—stores the selected city.
8. Open the **FormFieldsCollection** window from the activity **Properties** panel.
9. To define the dropdown fields in the form:
   * Define the dropdown fields. The **Name** you set is used for data binding (see **Dropdown Component** &gt; **Field Key** tab &gt; **Property name**).
   * Additionally, define the dropdown lists by appending `_dropdown` to the dropdown field name.
10. In the **Value** column, set the user selection as follows:
    * For the parent dropdown list, use the list defined at Step 1.
    * For the child dropdown list, use the variable stored at Step 7.
    * For the parent dropdown field, use the variable stored at Step 7.
    * For the child dropdown field, use the variable stored at Step 7.

    ![docs image](https://dev-assets.cms.uipath.com/assets/images/activities/activities-docs-image-178924-96cdc017.webp)
11. Click **OK**.

**Sample Workflow**

To check the complete workflow or to have a future reference, download the [XAML example](https://documentationexamplerepo.blob.core.windows.net/examples/Activities/ConditionalDropDowns_Sample.xaml)
