Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6943611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:10:44+00:00 2026-05-27T13:10:44+00:00

I have the following XAML inside a user control: <UserControl.Resources> <ObjectDataProvider x:Key=DataSources ObjectInstance={x:Static data:Sql.SqlDataSourceEnumerator.Instance}

  • 0

I have the following XAML inside a user control:

<UserControl.Resources>
    <ObjectDataProvider x:Key="DataSources" 
       ObjectInstance="{x:Static data:Sql.SqlDataSourceEnumerator.Instance}" 
       MethodName="GetDataSources" 
       IsAsynchronous="True"/>
</UserControl.Resources>

  …

<ComboBox Name="cboServer" IsEditable="True" 
      ItemsSource="{Binding Source={StaticResource DataSources}, Mode=OneWay}"
      DisplayMemberPath="ServerName" />

<ComboBox Name="cboInstance" IsEditable="True" 
      ItemsSource="{Binding Source={StaticResource DataSources}, Mode=OneWay}"
      DisplayMemberPath="InstanceName" />

This works, but now what I want to do is to filter the second box based on the first; so when the server is selected, the instances are filtered to show only those for that server.

Is there a way to do this without having to manually populate the second control?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T13:10:44+00:00Added an answer on May 27, 2026 at 1:10 pm

    Normally you might be able to do filtering like this using a CollectionViewSource, but unfortunately it looks like this won’t work here because SqlDataSourceEnumerator.GetDataSources() returns a DataTable, and the collection view type used with those doesn’t seem to support filtering.

    As I believe some of the other answers were suggesting, the best way to do this is probably to replace the ObjectDataProvider with your own view model class that can filter things appropriately. This will also let you do things like filtering out duplicate server names if a particular server has multiple instances.

    Here’s something that might work for you or at least get you started:

    public class ViewModel : INotifyPropertyChanged
    {
        private string _selectedServerName;
        private DataTable _dataSources;
    
        public IEnumerable<string> ServerNames
        {
            get
            {
                if (_dataSources == null)
                {
                    _dataSources = SqlDataSourceEnumerator.Instance.GetDataSources();
                }
                return _dataSources.Rows.Cast<DataRow>()
                    .Where(row => !row.IsNull("ServerName"))
                    .Select(row => (string)row["ServerName"]).Distinct();
            }
        }
    
        public string SelectedServerName
        {
            get { return _selectedServerName; }
            set
            {
                _selectedServerName = value;
                NotifyOfPropertyChange("SelectedServerName");
                NotifyOfPropertyChange("Instances");
            }
        }
    
        public IEnumerable<string> Instances
        {
            get
            {
                if (_dataSources == null || _selectedServerName == null) return new string[0];
                return _dataSources.Rows.Cast<DataRow>()
                    .Where(row => !row.IsNull("InstanceName") && _selectedServerName.Equals(row["ServerName"]))
                    .Select(row => (string)row["InstanceName"]);
            }
        }
    
        public event PropertyChangedEventHandler PropertyChanged;
    
        private void NotifyOfPropertyChange(string propertyName)
        {
            var handler = PropertyChanged;
            if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }
    

    You’d then need to change your XAML as follows (replacing the namespace declaration on the ViewModel with something appropriate for your project):

    <UserControl.Resources>
        <WpfApplication1:ViewModel x:Key="ViewModel" />
    </UserControl.Resources>
    
    <ComboBox Name="cboServer"
              IsEditable="True" 
              ItemsSource="{Binding ServerNames, Source={StaticResource ViewModel}, Mode=OneWay, IsAsync=True}"
              SelectedItem="{Binding SelectedServerName, Source={StaticResource ViewModel}, Mode=TwoWay}"/>
    
    <ComboBox Name="cboInstance" 
              IsEditable="True" 
              ItemsSource="{Binding Instances, Source={StaticResource ViewModel}, Mode=OneWay}" />
    

    Note that you’re binding both the ItemsSource and the SelectedItem properties on cboServer to properties on the ViewModel, and that the SelectedItem binding is two-way. This will feed the selected server name back to the ViewModel, which will then notify WPF that the Instances property has changed. The Instances property filters out any row that doesn’t match the selected server name.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following XAML/Control Template for a ListViewItem: <Window.Resources> <ControlTemplate x:Key=ItemTemplate TargetType=ListViewItem> <Border
Let's pretend I have the following xaml... <UserControl.Resources> <local:ViewModel x:Name=viewModel /> <local:LoadChildrenValueConverter x:Name=valueConverter />
I have the following XAML: <Window.Resources> <myApp:ImageDisplayConvertor x:Key=ImageDisplayConvertor /> </Window.Resources> <DataGridTemplateColumn Header=Icon> <DataGridTemplateColumn.CellTemplate >
I have a user control that inside has a TextBlock (textmsg), the following is
I have the following XAML code, which displays a picture (image inside borders) and
I have the following XAML for a databound items control to show a list
I have the following XAML: <UserControl x:Class=EMS.Controls.Dictionary.TOCControl xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:vm=clr-namespace:EMS.Controls.Dictionary.Models xmlns:diagnostics=clr-namespace:System.Diagnostics;assembly=WindowsBase x:Name=root > <TreeView
I have a custom Control which contains the generic.xaml inside the Themes folder. I
I have the following (condensed) silverlight xaml for a view / viewmodel: <UserControl x:Class=MyView>
I have custom control with following: <TextBox Grid.Column=3 Text={TemplateBinding SampleValue} /> public static readonly

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.