Select to view content in your preferred language

update second ComboBox???

1425
5
08-20-2010 03:29 AM
LemvigKommune
Deactivated User
Hi all

I'm trying to get a second combobox to updata and show data selected on the value from combobox 1

heres my code

mainpage.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using ESRI.ArcGIS.Client.Tasks;
using ESRI.ArcGIS.Client;

namespace ListTest
{
       
    public partial class MainPage : UserControl
    {
        public List<string> stateNameQuery = new List<string>();
        public MainPage()
        {
            InitializeComponent();

            QueryTask queryTask = new QueryTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer/2");
            queryTask.ExecuteCompleted += QueryTask_ExecuteCompleted;
            queryTask.Failed += QueryTask_Failed;

            ESRI.ArcGIS.Client.Tasks.Query query = new ESRI.ArcGIS.Client.Tasks.Query();
            query.ReturnGeometry = true;
            query.OutFields.AddRange(new string[] { "STATE_NAME" });
            
            //query all features
            query.Where = "1=1";
            queryTask.ExecuteAsync(query);
            
            vejComboBox.ItemsSource = stateNameQuery;
            
        }

        void QueryTask_ExecuteCompleted(object sender, ESRI.ArcGIS.Client.Tasks.QueryEventArgs args)
        {
            FeatureSet featureSet = args.FeatureSet;
            if (featureSet != null && featureSet.Features.Count > 0)

                //add result to list
                foreach (Graphic resultFeature in args.FeatureSet.Features)
                {
                    stateNameQuery.Add(resultFeature.Attributes["STATE_NAME"].ToString());
                }

            else
                MessageBox.Show("No features returned from query");

        }

        private void QueryTask_Failed(object sender, TaskFailedEventArgs args)
        {
            MessageBox.Show("Query execute error: " + args.Error);
        }

        private void comboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            
        }

    }
}

mainpage.xaml
<UserControl x:Class="ListTest.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:esri="http://schemas.esri.com/arcgis/client/2009"
    xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
    xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data" mc:Ignorable="d" d:DesignHeight="252" d:DesignWidth="835">

    <Grid x:Name="LayoutRoot" Background="White" Height="250" Width="836" VerticalAlignment="Top">
        <ComboBox x:Name="vejComboBox" 
                  Width="200" Height="32" 
                  Margin="218,12,418,0" 
                  VerticalAlignment="Top" />
        <ComboBox x:Name="comboBox1" 
                  VerticalAlignment="Top"  
                  Height="32" Width="200"
                  Margin="424,12,212,0" 
                  SelectionChanged="comboBox1_SelectionChanged"/>
    </Grid>
</UserControl>


and can this be convertet to autocompleteboxes ???

Thanks in advance

Mads Gren
Denmark.
0 Kudos
5 Replies
JenniferNery
Esri Regular Contributor
If you make your stateNameQuery an ObservableCollection and have both combobox ItemSource set to this, you can set the second combobox SelectedItem="{Binding ElementName=vejComboBox, Path=SelectedItem, Mode=TwoWay}".

It might also be a good idea to check for duplicates, before adding to your stateNameQuery.

To make the combobox editable and autocomplete, you will need to create your own style. You can read up on it here: http://silverlightfeeds.com/post/53/Use_Styles_for_an_editable_Silverlight_ComboBox.aspx
0 Kudos
gabrielvazquez
Deactivated User
MadsGren,

Did you have any success in completing these? I am in the process of doing something very similiar.
0 Kudos
LemvigKommune
Deactivated User
Hi Gabirel

Sorry, but no, I've decided to return to Adobe FLEX and the FLEX viewer.

Mads
0 Kudos
gabrielvazquez
Deactivated User
I was trying to do something similiar, sort of a cascading query that uses multiple comboboxes based on location. From Country, to State, to City, then to incidents within the specific city.

Since I was pulling the data from an ArcGIS Server, I pulled all of Outfields for the query.

On the executedComplete, I sort the initial country field.
var countries = (from g in args.FeatureSet.Features
                        select g.Attributes["CountryName"]).Distinct().OrderBy(s => s);
CountryComboBox.ItemsSource = countries;

//I define the default combobox item as the UnitedStates
CountryComboBox.SelectedItem = "United States";

//here I add the state combobox items based on the country selection

if (CountryComboBox.SelectedItem != null)
{




}
0 Kudos
gabrielvazquez
Deactivated User
I was trying to do something similiar, sort of a cascading query that uses multiple comboboxes based on location. From Country, to State, to City, then to incidents within the specific city.

Since I was pulling the data from an ArcGIS Server, I pulled all of Outfields for the query.
InitialQuery.OutFields.AddRange(new string)[] {"GISIncidentTypeName", "LocationName", etc...});

On the executedComplete, I sort the initial country field and subordinate fields.

var countries = (from g in args.FeatureSet.Features
                        select g.Attributes["CountryName"]).Distinct().OrderBy(s => s);
CountryComboBox.ItemsSource = countries;

//I define the default combobox item as the UnitedStates
CountryComboBox.SelectedItem = "United States";

//here I add the state combobox items based on the country selection

if (CountryComboBox.SelectedItem != null)
{
var states2 =
(from g in args.FeatureSet.Features
where g.Attributes["CountryName"].ToString() == CountryComboBox.SelectedItem.ToString()
select g.Attributes["GISStateName"]).Distinct().OrderBY(s=>s);
StateComboBox.ItemsSource = states2;
}

I go on to define the initial results for each of the comboboxes upon query panel load. I also create combobox selection changes for each of comboboxes, and define the item results for each of the subordinate fields. It works fine, but I'm not sure if anyone has any recommendations on how to do this easier.
0 Kudos