# C# Dropdown

**URL:** <https://forum.dynamobim.com/t/c-dropdown/17503>\
**Category:** Revit\
**Created:** [December 15, 2017, 3:25pm UTC](https://forum.dynamobim.com/t/c-dropdown/17503 "2017-12-15T15:25:00Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![taavilooke](https://avatars.discourse-cdn.com/v4/letter/t/7feea3/32.png) [@taavilooke](https://forum.dynamobim.com/u/taavilooke)\
**Post date:** [December 19, 2017, 9:23am UTC](https://forum.dynamobim.com/t/c-dropdown/17503/6 "2017-12-19T09:23:39Z")

</div>

I figured it out now. It is important that the BuildOutputAst is able to return a null node, in case the SelectedIndex is -1. Also had to make constructor public (Can’t understand how I missed it earlier 😃 ). This is the code that works:

```
public class DummyDropdown : DSDropDownBase
{
    public DummyDropdown() : base("Name of the output") { }

    protected override SelectionState PopulateItemsCore(string currentSelection)
    {
        Items.Clear();
        Dictionary<string, int> dropdownItems = new Dictionary<string, int> {
            { "Test1", 1 },
            { "Test2", 2 },
            { "Test3", 3 },
            { "Test4", 4 },
        };
        foreach (KeyValuePair<string, int> item in dropdownItems)
        {
            Items.Add(new DynamoDropDownItem(item.Key, item.Value));
        }
        return SelectionState.Restore;
    }

    public override IEnumerable<AssociativeNode> BuildOutputAst(List<AssociativeNode> inputAstNodes )
    {
        if (Items.Count == 0 ||
            SelectedIndex == -1) //NB! This line is crucial for some reason
        {
            return new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), AstFactory.BuildNullNode()) };
        }

        var intNode = AstFactory.BuildIntNode((int)Items[SelectedIndex].Item);
        var assign = AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), intNode);
        return new List<AssociativeNode> { assign };
    }
}
```

---

_[View the full topic](https://forum.dynamobim.com/t/c-dropdown/17503)._
