# Dropdown Question

**URL:** <https://forum.inductiveautomation.com/t/dropdown-question/10617>\
**Category:** Ignition\
**Created:** [October 13, 2015, 8:36pm UTC](https://forum.inductiveautomation.com/t/dropdown-question/10617 "2015-10-13T20:36:08Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![alewayhar](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@alewayhar](https://forum.inductiveautomation.com/u/alewayhar)\
**Post date:** [October 13, 2015, 8:36pm UTC](https://forum.inductiveautomation.com/t/dropdown-question/10617/1 "2015-10-13T20:36:08Z")

</div>

I’m working with a dropdown menu and it is getting it’s data from a SQL query. When i start the program, it automatically selects one of the values. How do I make it so that ‘no selection’ is an option? And this option have a respective value? Any thoughts other than just creating a new entry in my Database that will pull it? Thanks so much!

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [October 13, 2015, 8:38pm UTC](https://forum.inductiveautomation.com/t/dropdown-question/10617/2 "2015-10-13T20:38:12Z")

</div>

Hi Alex!

Just ran into the same thing recently-- shooting my own foot there! 😆

In the designer, set the selected index to -1, then save the project.

---

<div class="post-metadata">

**Author:** ![alewayhar](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@alewayhar](https://forum.inductiveautomation.com/u/alewayhar)\
**Post date:** [October 13, 2015, 8:44pm UTC](https://forum.inductiveautomation.com/t/dropdown-question/10617/3 "2015-10-13T20:44:08Z")

</div>

So now I feel silly, because I can’t even find that option under my property editor ![:/](https://us1.discourse-cdn.com/inductiveautomation/original/1X/8e510869ae26fbd7ab76e1e731ceea2054ef109c.gif "Hrm") Does my selection mode need to be on a certain setting? It’s on lenient, and the no selection value is -1. Still only displaying the 3 results returned from the query and not a 4th, ‘’ option. Does that make sense?

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [October 13, 2015, 8:52pm UTC](https://forum.inductiveautomation.com/t/dropdown-question/10617/4 "2015-10-13T20:52:03Z")

</div>

Sorry, Alex, I misspoke-- or mis-typed…

Selected Value is the one you want. It’s right underneath Data

---

<div class="post-metadata">

**Author:** ![alewayhar](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@alewayhar](https://forum.inductiveautomation.com/u/alewayhar)\
**Post date:** [October 13, 2015, 9:22pm UTC](https://forum.inductiveautomation.com/t/dropdown-question/10617/5 "2015-10-13T21:22:48Z")

</div>

Ok, I see that and I see what it is doing on startup, but is there a way to make it a permanent option? After I select an option, the option is no longer available and it cannot be chosen. I’m trying to figure out a way to make my SQL dynamic by being able to filter a table based on a column (which I am currently doing), but I want one of the options to include all of the options and return all of the rows. I thought that by making the selected string value of a \* , I would be able to essentially return all rows of a table.

Maybe there is an easier way to do this? ![:scratch:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/76d1620bec252bfac07050c889ff5a91dc8a9c25.gif ":scratch:")

---

<div class="post-metadata">

**Author:** ![Pam3636](https://avatars.discourse-cdn.com/v4/letter/p/bc79bd/32.png) [@Pam3636](https://forum.inductiveautomation.com/u/Pam3636)\
**Post date:** [October 14, 2015, 1:31am UTC](https://forum.inductiveautomation.com/t/dropdown-question/10617/6 "2015-10-14T01:31:21Z")

</div>

I’m not sure if this will work in your project, but in my dropdown scripting I added the line:

event.source.selectedValue = -1

and it seemed to work for me. Sets the index back to -1 after it goes through the rest of the script.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [October 14, 2015, 10:50am UTC](https://forum.inductiveautomation.com/t/dropdown-question/10617/7 "2015-10-14T10:50:56Z")

</div>

Ah! I see what you mean, Alex.

I use something like this for the Data property:

`SELECT 'All'
UNION ALL
SELECT DISTINCT column_name
FROM table`  
This will put the option ‘All’ at the top. You can then modify your where clause to fit what you want to do.

Hope this helps!

---

<div class="post-metadata">

**Author:** ![alewayhar](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@alewayhar](https://forum.inductiveautomation.com/u/alewayhar)\
**Post date:** [October 14, 2015, 1:44pm UTC](https://forum.inductiveautomation.com/t/dropdown-question/10617/8 "2015-10-14T13:44:31Z")

</div>

This is the SQL Query for the table I have on my page

`SELECT * FROM workorders
WHERE clientname = '{Root Container.Dropdown.selectedStringValue}'
AND problem LIKE '%{Root Container.Text Field.text}%'`

My WHERE statement is looking at the dropdown menu for the value in client name. Since I do not have any clients with the name ‘ALL’ it won’t return all of the values. I’m sure there is a better way to do this. Honestly, it’s not a huge problem if i don’t get it working, it would just allow me to search across all entries based on the search parameter instead of limiting it to just the one client.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [October 14, 2015, 2:01pm UTC](https://forum.inductiveautomation.com/t/dropdown-question/10617/9 "2015-10-14T14:01:18Z")

</div>

You can use a custom property to hold the WHERE clause.

`if({Root Container.Dropdown.selectedStringValue}="All",
    "",
    CONCAT("WHERE column_name = ", {Root Container.Dropdown.selectedStringValue})
  )
`

Then your query would be something like:

```auto
SELECT *
FROM table
{Root Container.whereClause}
```

---

<div class="post-metadata">

**Author:** ![DougSN](https://avatars.discourse-cdn.com/v4/letter/d/a9adbd/32.png) [@DougSN](https://forum.inductiveautomation.com/u/DougSN)\
**Post date:** [December 3, 2015, 9:00pm UTC](https://forum.inductiveautomation.com/t/dropdown-question/10617/10 "2015-12-03T21:00:36Z")

</div>

Another solution would be to form your query like this.

`SELECT * FROM workorders
WHERE (clientname = '{Root Container.Dropdown.selectedStringValue}' OR '{Root Container.Dropdown.selectedStringValue}' = 'All')
AND problem LIKE '%{Root Container.Text Field.text}%'`
