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 869727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:21:21+00:00 2026-05-15T10:21:21+00:00

Ok the title maybe a little confusing. I have a database with the table

  • 0

Ok the title maybe a little confusing. I have a database with the table Companies wich has one-to-many relotionship with another table Divisions ( so each company can have many divisions ) and division will have many employees.

I have a ListView of the companies. What I wan’t is that when I choose a company from the ListView another ListView of divisions within that company appears below it. Then I pick a division and another listview of employees within that division appaers below that. You get the picture.

Is there anyway to do this mostly inside the XAML code declaritively (sp?). I’m using linq so the Company entity objects have a property named Division wich if I understand linq correctly should include Division objects of the divisions connected to the company. So after getting all the companies and putting them as a itemsource to CompanyListView this is where I currently am.

   <ListView x:Name="CompanyListView"
              DisplayMemberPath="CompanyName"
              Grid.Row="0" Grid.Column="0" />

    <ListView DataContext="{Binding ElementName=CompanyListView, Path=SelectedItem}"
              DisplayMemberPath="Division.DivisionName"
              Grid.Row="1" Grid.Column="0" />

I know I’m way off but I was hoping by putting something specific in the DataContext and DisplayMemberPath I could get this to work. If not then I have to capture the Id of the company I guess and capture a select event or something.

Another issue but related is the in the seconde column besides the lisview I wan’t to have a details/edit view for the selected item. So when only a company is selected details about that will appear then when a division under the company is picked It will go there instead, any ideas?

  • 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-15T10:21:21+00:00Added an answer on May 15, 2026 at 10:21 am

    You can use the MVVM pattern to bind your XAML to a class that contains information for your ListViews and reset the content for the Division collection based on the selected Comany item.

    Here is a basic sample to get you started.

    Here are two ListView controls in XAML:

    <Window x:Class="MultiListView.Views.MainView"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Title="Main Window" Height="400" Width="800">
      <DockPanel>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <ListView Grid.Row="0" 
                      ItemsSource="{Binding Companies}"
                      SelectedItem="{Binding Company, Mode=TwoWay}">
                <ListView.View>
                    <GridView>
                        <GridViewColumn Header="Name"
                                        DisplayMemberBinding="{Binding CompanyName}" />
                        <GridViewColumn Header="Description"
                                        DisplayMemberBinding="{Binding Description}" />
                    </GridView>
                </ListView.View>
            </ListView>
            <ListView Grid.Row="1" 
                      ItemsSource="{Binding Divisions}"
                      SelectedItem="{Binding Division, Mode=TwoWay}">
                <ListView.View>
                    <GridView>
                        <GridViewColumn Header="Name"
                                        DisplayMemberBinding="{Binding DivisionName}" />
                        <GridViewColumn Header="Description"
                                        DisplayMemberBinding="{Binding Description}" />
                    </GridView>
                </ListView.View>
            </ListView>
        </Grid>
      </DockPanel>
    </Window>
    

    In the code-behind set the DataContext for the Window to a class the contains the binding references used in the XAML.

    public partial class MainView : Window
    {
       MainViewModel _mvm = new MainViewModel();
    
       public MainView()
       {
          InitializeComponent();
          DataContext = _mvm;
       }
    }
    

    The following class uses the MVVM pattern, which you can find lots of information
    on in StackOverFlow. This class contains the data that the XAML binds with. Here
    is where you can use LINQ to load/reload the collections.

    using System.Collections.ObjectModel;
    using MultiListView.Models;
    
    namespace MultiListView.ViewModels
    {
    public class MainViewModel : ViewModelBase
    {
      public MainViewModel()
      {
         _companies = new ObservableCollection<Company>();
         _companies.Add(new Company("Stackoverflow", "QA web site"));
         _companies.Add(new Company("Fog Creek", "Agile Bug Tracking"));
         _companies.Add(new Company("Second Beach", "Not sure yet"));
    
         _divisions = new ObservableCollection<Division>();
      }
    
      private ObservableCollection<Company> _companies;
      public ObservableCollection<Company> Companies
      {
         get { return _companies; }
         set
         {
            _companies = value;
            OnPropertyChanged("Companies");
         }
      }
    
      private Company _company;
      public Company Company
      {
         get { return _company; }
         set
         {
            _company = value;
    
            // load/reload divisions for the selected company here
            LoadDivisions();
    
            OnPropertyChanged("Company");
         }
      }
    
      // hack to keep the example simpe...
      private void LoadDivisions()
      {
         _divisions.Clear();
    
         // use db or linq here to filiter property
         if ( _company != null )
         {
            if ( _company.CompanyName.Equals("Stackoverflow") )
            {
               _divisions.Add( new Division("QA", "Test all day"));
               _divisions.Add( new Division("Write", "Doc all day"));
               _divisions.Add( new Division("Code", "Code all day"));
            }
            else if (_company.CompanyName.Equals("Fog Creek"))
            {
               _divisions.Add(new Division("Test", "Test all day"));
               _divisions.Add(new Division("Doc", "Doc all day"));
               _divisions.Add(new Division("Develop", "Code all day"));
            }
            else if (_company.CompanyName.Equals("Second Beach"))
            {
               _divisions.Add(new Division("Engineering", "Code all day"));
            }
         }
      }
    
      private ObservableCollection<Division> _divisions;
      public ObservableCollection<Division> Divisions
      {
         get { return _divisions; }
         set
         {
            _divisions = value;
            OnPropertyChanged("Divisions");
         }
      }
    
      private Division _division;
      public Division Division
      {
         get { return _division; }
         set
         {
            _division = value;
            OnPropertyChanged("Division");
         }
      }
    }
    }
    

    OnPropertyChanged implements INotifyPropertyChanged.
    When the properties of a ViewModel change, the Views bound to the ViewModel receive a notification when the ViewModel raises its PropertyChanged event.

    You can find examples in most MVVM libraries, or look to MSDN for an example.

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

Sidebar

Related Questions

Title might be a bit confusing, so let me explain. I have a website
The title may be a little confusing, but I don't know how else to
Title pretty much sums it up. The external style sheet has the following code:
Sorry for the confusing title.... We are developing an application to be used by
One thing with which I have long had problems, within the CakePHP framework, is
OK so that title sucks a little but I could not think of anything
Maybe I should back-up and widen the scope before diving into the title question...
May be my title is not clear. I am looking for some kind of
Title is the entire question. Can someone give me a reason why this happens?
Title says what i'm trying to do. I can successfully generate an assembly if

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.