Populate a combo box with unique values using a query layer

In an earlier post, we showed how to populate a ComboBox with a set of unique values from a map service by querying the service and manipulating the data in the browser to generate the unique list. At ArcGIS 10, we can use a Query Layer to accomplish this task in a more straightforward manner. Let’s look at how we can use query layers to fill a combo box with a series of dams in the Pacific Northwest.

Query Layer

First we’ll create a new query layer using ArcMap. A query layer is a layer or table that is created using a SQL Query. We can use the SQL SELECT DISTINCT statement to generate a list of unique values from the specified field or fields. In this example we create a new query layer that contains a list of unique dam names.

After adding the query layer to the map, we’ll publish the map. The published map service “FishCount” contains a layer with counts of several fish species at each dam, plus a table with unique dam names. The snippet below queries the table of unique dam names to retrieve all the records.