# Creating Dependent Drop Down Lists/Enum based on previous list

**URL:** <https://forum.opentap.io/t/creating-dependent-drop-down-lists-enum-based-on-previous-list/1277>\
**Category:** Technical\
**Created:** [October 20, 2023, 10:43pm UTC](https://forum.opentap.io/t/creating-dependent-drop-down-lists-enum-based-on-previous-list/1277 "2023-10-20T22:43:28Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![ipa\_test](https://avatars.discourse-cdn.com/v4/letter/i/3e96dc/32.png) [@ipa\_test](https://forum.opentap.io/u/ipa_test)\
**Post date:** [October 20, 2023, 10:43pm UTC](https://forum.opentap.io/t/creating-dependent-drop-down-lists-enum-based-on-previous-list/1277/1 "2023-10-20T22:43:28Z")

</div>

I am trying to create a generic paramaters “form” at the start of my test. These selected parameters will be used to build a JSON file for passing into my software package, and also ultimately for sending commands to the DUT as part of the Testing.

The challenge is that I have a hierarchical set of selections, for example:  
1.) First Select Test Standard  
2.) This will then limit the selection of DUT Types  
3.) The DUT Type will then limit the selection of Modulation Formats  
4.) The Modulation formats will then limit the selection of Data Rates.

I have tried this with Lists using Dictionary entries, and with enums. At least with enums, I can get the displayed lists to change based on the scenario above, and have no luck figuring out how to do that using lists.

With the enums, however, it is possible that the data rates could be the same for different DUT Types and modulation formats, thus my trying to use multiple conditions in the EnableIf statement, but that does not seem to be working. Here is an example of the Display code I used for one of the Data Rate choices:

[Display(“54”, “Shows the use of available values attribute.”, Order: 2.312, Group: “Data Rate”)]  
[EnabledIf(“DutType2G”, DUTType2G.WLAN2\_4GHz, “DutType5G”, DUTType5G.WLAN\_5GHz\_20MHz, HideIfDisabled = true)]  
[EnabledIf(“Standard”, StandardVersion.EN\_300\_328, “Standard”, StandardVersion.EN\_301\_893, HideIfDisabled = true)]  
[EnabledIf(“ModulationWiFi5G20”, ModulationWiFi5G20.\_11a20\_Band1\_2, “ModulationWiFi5G20”, ModulationWiFi5G20.\_11a20\_Band3,  
“ModulationWiFi5G20”, ModulationWiFi5G20.\_11a20\_Band4, “ModulationWiFi2G”, ModulationWiFi2G.\_11g, HideIfDisabled = true)]  
public bool DataRate54 { get; set; }

That does not seem to be working.

Does anyone have examples of how to enable hierarchical drop down lists?

---

<div class="post-metadata">

**Author:** ![rolf\_madsen](https://avatars.discourse-cdn.com/v4/letter/r/43a26b/32.png) [@rolf\_madsen](https://forum.opentap.io/u/rolf_madsen)\
**Post date:** [October 21, 2023, 7:15am UTC](https://forum.opentap.io/t/creating-dependent-drop-down-lists-enum-based-on-previous-list/1277/2 "2023-10-21T07:15:46Z")

</div>

Hi @ipa_test,

It sounds a bit like you should be using AvailableValuesAttribute. Did you check that out?

Works like this:

```cs

public int[] AvailableInts => {1,2,3}

// SelectedInt should show up as a drop down with 1,2,3 as available options.
[AvailableValues(nameof(AvailableInts))]
public int SelectedInt{get;set;}

```

---

<div class="post-metadata">

**Author:** ![ipa\_test](https://avatars.discourse-cdn.com/v4/letter/i/3e96dc/32.png) [@ipa\_test](https://forum.opentap.io/u/ipa_test)\
**Post date:** [October 21, 2023, 7:50pm UTC](https://forum.opentap.io/t/creating-dependent-drop-down-lists-enum-based-on-previous-list/1277/3 "2023-10-21T19:50:00Z")

</div>

I have tried that, but again, how do I select the second drop down list based on the selected value in the first list? And so on…

---

<div class="post-metadata">

**Author:** ![rolf\_madsen](https://avatars.discourse-cdn.com/v4/letter/r/43a26b/32.png) [@rolf\_madsen](https://forum.opentap.io/u/rolf_madsen)\
**Post date:** [October 21, 2023, 9:42pm UTC](https://forum.opentap.io/t/creating-dependent-drop-down-lists-enum-based-on-previous-list/1277/4 "2023-10-21T21:42:27Z")

</div>

Ok, so if I understand you correctly, you want to derive the second list of available values based on the first selected.

The AvailableInts can do any kind of calculation available to the step. it can also calculate it based on other settings. See SelectedInt2 below.

```csharp
public int[] AvailableInts => {1,2,3}

[AvailableValues(nameof(AvailableInts))]
public int SelectedInt{get;set;}

public int[] AvailableInts2 => new int[]{SelectedInt * 2,SelectedInt * 3,SelectedInt * 4};

// SelectedInts2 is based on the value of SelectedInt
[AvailableValues(nameof(AvailableInts2))]
public int SelectedInt2{get;set;}

```

So now, depending on what I choose first, the available selection for the second will change.

---

<div class="post-metadata">

**Author:** ![ipa\_test](https://avatars.discourse-cdn.com/v4/letter/i/3e96dc/32.png) [@ipa\_test](https://forum.opentap.io/u/ipa_test)\
**Post date:** [October 22, 2023, 6:09pm UTC](https://forum.opentap.io/t/creating-dependent-drop-down-lists-enum-based-on-previous-list/1277/5 "2023-10-22T18:09:16Z")

</div>

Well, that is kind of what I am trying to do, but it is a little more complicated than that, for example what i need to be able to do is:  
if(SelectedInt == 1)  
{  
AvailableDUT = new string List (DUTTYPE1);  
}  
else  
{  
AvailableDUT = new stringList(DUTTYPE2);  
}

I have yet to figure out how to do this…

---

<div class="post-metadata">

**Author:** ![rolf\_madsen](https://avatars.discourse-cdn.com/v4/letter/r/43a26b/32.png) [@rolf\_madsen](https://forum.opentap.io/u/rolf_madsen)\
**Post date:** [October 22, 2023, 7:52pm UTC](https://forum.opentap.io/t/creating-dependent-drop-down-lists-enum-based-on-previous-list/1277/6 "2023-10-22T19:52:47Z")

</div>

So which part of this doesn’t work? I would probably do it in the getter of AvailableDUT and not in a setter, but I think it should work.

---

<div class="post-metadata">

**Author:** ![ipa\_test](https://avatars.discourse-cdn.com/v4/letter/i/3e96dc/32.png) [@ipa\_test](https://forum.opentap.io/u/ipa_test)\
**Post date:** [October 22, 2023, 8:28pm UTC](https://forum.opentap.io/t/creating-dependent-drop-down-lists-enum-based-on-previous-list/1277/7 "2023-10-22T20:28:24Z")

</div>

I can’t do an ‘If’ in the #region to set-up the form, I can’t figure out how to call a method to do the If statement… I am new to TAP and C#, so I am stumbling alot.

---

<div class="post-metadata">

**Author:** ![rolf\_madsen](https://avatars.discourse-cdn.com/v4/letter/r/43a26b/32.png) [@rolf\_madsen](https://forum.opentap.io/u/rolf_madsen)\
**Post date:** [October 22, 2023, 8:51pm UTC](https://forum.opentap.io/t/creating-dependent-drop-down-lists-enum-based-on-previous-list/1277/8 "2023-10-22T20:51:12Z")

</div>

That’s fair. Don’t worry, we’ll get you through this 🙂

C# as a language has evolved over time, so now there are more than one way of expressing the same thing. Which I think may be confusing you in this case.

This also applies to C# properties, which are used for settings.

So to clarify, this:

```cs
public int[] AvailableInts2 => new int[]{SelectedInt * 2,SelectedInt * 3,SelectedInt * 4};

```

Is 100% the same as this:

```cs
public int[] AvailableInts2 
{
   get
   {
       return new int[]{SelectedInt * 2,SelectedInt * 3,SelectedInt * 4};
   }
}

```

And it is inside that ‘getter’ I recommend you to add the if-code. For example:

````cs
```cs
public string[] AvailableInts2 
{
   get
   {
      if(SelectedInt == 1){
          return new string[]{"DUT1", "DUT3"};
      }
      return new string[]{"DUT2", "DUT3", "DUT4"};
    }
}

````

---

<div class="post-metadata">

**Author:** ![ipa\_test](https://avatars.discourse-cdn.com/v4/letter/i/3e96dc/32.png) [@ipa\_test](https://forum.opentap.io/u/ipa_test)\
**Post date:** [October 22, 2023, 9:03pm UTC](https://forum.opentap.io/t/creating-dependent-drop-down-lists-enum-based-on-previous-list/1277/9 "2023-10-22T21:03:50Z")

</div>

I am trying that now, but I get an error around:  
if(SelectedInt == 1)

Says there is ambiguity between that SelectedInt and the other SelectedInt at the end of the first list…

---

<div class="post-metadata">

**Author:** ![ipa\_test](https://avatars.discourse-cdn.com/v4/letter/i/3e96dc/32.png) [@ipa\_test](https://forum.opentap.io/u/ipa_test)\
**Post date:** [October 22, 2023, 9:04pm UTC](https://forum.opentap.io/t/creating-dependent-drop-down-lists-enum-based-on-previous-list/1277/10 "2023-10-22T21:04:23Z")

</div>

And, BTW, thanks for your help. I have been wasting over 6 weeks time trying to figure this out…

---

<div class="post-metadata">

**Author:** ![ipa\_test](https://avatars.discourse-cdn.com/v4/letter/i/3e96dc/32.png) [@ipa\_test](https://forum.opentap.io/u/ipa_test)\
**Post date:** [October 22, 2023, 9:14pm UTC](https://forum.opentap.io/t/creating-dependent-drop-down-lists-enum-based-on-previous-list/1277/11 "2023-10-22T21:14:02Z")

</div>

Okay, I have figured out how to get the errors to clear, and this is the type of logic I want to implement, but still not sure if it is doing what I need it to do…

public Dut SelectedDut { get; set; }  
[XmlIgnore]  
//[Browsable(false)]  
private List \_listOfAvailableDUTTypes;  
[Display(“Available Values”, “An editable list of values.”)]  
public List ListOfAvailableDUTTypes  
{  
get  
{  
if (SelectedValue == “One”)  
{  
return new List{ “DUT1”, “DUT2”, “DUT3” };  
}  
else if(SelectedValue == “Two”)  
{  
return new List { “DUT27”, “DUT28”, “DUT30” };  
}  
else  
{  
return new List { “Scope”, “Signal Analzyer”, “VSG” };  
}  
}  
set  
{  
\_listOfAvailableValues = value;  
OnPropertyChanged(“ListOfAvailableDUTTypes”);  
}  
}

---

<div class="post-metadata">

**Author:** ![rolf\_madsen](https://avatars.discourse-cdn.com/v4/letter/r/43a26b/32.png) [@rolf\_madsen](https://forum.opentap.io/u/rolf_madsen)\
**Post date:** [October 22, 2023, 9:22pm UTC](https://forum.opentap.io/t/creating-dependent-drop-down-lists-enum-based-on-previous-list/1277/12 "2023-10-22T21:22:41Z")

</div>

OK, well, I am sorry it took that long. Did you find the examples included in the SDK package?

You write:

```cs
[Display(“Available Values”, “An editable list of values.”)]
public List ListOfAvailableDUTTypes

```

If you want it to be editable, this is not the right approach. Whenever the getter is called a new list is created (happens very often).

So do you want the user to edit the list or do you want it to be generated automatically?

---

<div class="post-metadata">

**Author:** ![ipa\_test](https://avatars.discourse-cdn.com/v4/letter/i/3e96dc/32.png) [@ipa\_test](https://forum.opentap.io/u/ipa_test)\
**Post date:** [October 22, 2023, 9:26pm UTC](https://forum.opentap.io/t/creating-dependent-drop-down-lists-enum-based-on-previous-list/1277/13 "2023-10-22T21:26:29Z")

</div>

I need the list to be generated automatically, and yes, I am using the example from the SDK… In fact, I would like to have the list pulled from the Dictionary set-up I have…

---

<div class="post-metadata">

**Author:** ![rolf\_madsen](https://avatars.discourse-cdn.com/v4/letter/r/43a26b/32.png) [@rolf\_madsen](https://forum.opentap.io/u/rolf_madsen)\
**Post date:** [October 22, 2023, 9:33pm UTC](https://forum.opentap.io/t/creating-dependent-drop-down-lists-enum-based-on-previous-list/1277/14 "2023-10-22T21:33:52Z")

</div>

Ok, in that case you dont need the setter part:

```cs
 set{ /*...*/}

```

Otherwise I think it looks good. If you need to pull the values from a dictionary you can do:

```cs
get
{
   // Assuming the dictionary keys matches the type of the property.
    return myDictionary.Keys; 
}

```

---

<div class="post-metadata">

**Author:** ![ipa\_test](https://avatars.discourse-cdn.com/v4/letter/i/3e96dc/32.png) [@ipa\_test](https://forum.opentap.io/u/ipa_test)\
**Post date:** [October 22, 2023, 10:04pm UTC](https://forum.opentap.io/t/creating-dependent-drop-down-lists-enum-based-on-previous-list/1277/15 "2023-10-22T22:04:50Z")

</div>

So, nothing goes in the set branch?

---

<div class="post-metadata">

**Author:** ![ipa\_test](https://avatars.discourse-cdn.com/v4/letter/i/3e96dc/32.png) [@ipa\_test](https://forum.opentap.io/u/ipa_test)\
**Post date:** [October 22, 2023, 10:12pm UTC](https://forum.opentap.io/t/creating-dependent-drop-down-lists-enum-based-on-previous-list/1277/16 "2023-10-22T22:12:39Z")

</div>

Holy crap, that looks like that might work… Thank you!

---

<div class="post-metadata">

**Author:** ![rolf\_madsen](https://avatars.discourse-cdn.com/v4/letter/r/43a26b/32.png) [@rolf\_madsen](https://forum.opentap.io/u/rolf_madsen)\
**Post date:** [October 23, 2023, 6:11am UTC](https://forum.opentap.io/t/creating-dependent-drop-down-lists-enum-based-on-previous-list/1277/17 "2023-10-23T06:11:10Z")

</div>

That’s great!

What I meant is, you can remove the ‘setter’ entirely. e.g:

```cs
// this is a get-only property (setter is removed):
string[] ListOfAvailableDutTypes
{
  get
  {
     return myDict.Keys;
  }
}

```
