Populate a XAML combo box with field names from a dataset?

3092
11
09-13-2011 09:35 AM
JonathanHouck
New Contributor III
Hello everyone,

This is all using Silverlight 4 with the REST API and C# code behind.

I'm trying to populate a combobox with all the field names from a dataset so I can capture the user's selection and pass it into a query that they have constructed on their own.

I can't figure out how to get an array or list (or anything) with the field names that I can then iteratively add to the combobox.Items.  I've got some queries set up in my other project but they're querying against rows (features) and not just against the field names. I don't want to hard code any field names because I want the box to populate dynamically depending on which dataset they want to query.

Am I going about this wrong or just missing something obvious? Thanks for your help.

Jon
0 Kudos
11 Replies
LanceCrumbliss
Occasional Contributor II
Hi All,

I am usingthe following code to try to populate a combo box as explaned in this thread. The combobox populates but all the entries are "ESRI.ArcGIS.Client.Field". I can not figure out how to populate the box with the field values. Any ideas..

QueryComboBox.ItemsSource = (MapApplication.Current.SelectedLayer as FeatureLayer).LayerInfo.Fields;


What happens if you set the ComboBox's DisplayMemberPath to "Name"?
0 Kudos
BrianLeroux
Occasional Contributor III
What happens if you set the ComboBox's DisplayMemberPath to "Name"?


Thanks for the suggestion. I will give it a try when I have a chance. I was able to populate my combo box with the following code.
private void updateQueryCombo()
        {
            foreach (Field field in (MapApplication.Current.SelectedLayer as FeatureLayer).LayerInfo.Fields)
            {
                QueryComboBox.Items.Add(field.Name.ToString());
            }
        }
0 Kudos