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

  • Home
  • SEARCH
  • 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 180465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:35:29+00:00 2026-05-11T14:35:29+00:00

I have two ObservableCollections and I need to show them in one ListView control

  • 0

I have two ObservableCollections and I need to show them in one ListView control together. For this purpose I created MergedCollection which presents these two collections as one ObservableCollection. This way I can set the ListView.ItemsSource to my merged collection and both collections are listed. Adding works fine but when I try to Remove an item, unhandled exception is shown:

An unhandled exception of type 'System.InvalidOperationException' occurred in PresentationFramework.dll Additional information: Added item does not appear at given index '2'. 

The code of MergedCollection follows:

public class MergedCollection : IEnumerable, INotifyCollectionChanged {     ObservableCollection<NetworkNode> nodes;     ObservableCollection<NodeConnection> connections;      public MergedCollection(ObservableCollection<NetworkNode> nodes, ObservableCollection<NodeConnection> connections)     {         this.nodes = nodes;         this.connections = connections;          this.nodes.CollectionChanged += new NotifyCollectionChangedEventHandler(NetworkNodes_CollectionChanged);         this.connections.CollectionChanged += new NotifyCollectionChangedEventHandler(Connections_CollectionChanged);     }      void NetworkNodes_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)     {         CollectionChanged(this, e);     }      void Connections_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)     {         CollectionChanged(this, e);     }      #region IEnumerable Members      public IEnumerator GetEnumerator()     {         for (int i = 0; i < connections.Count; i++)         {             yield return connections[i];         }          for (int i = 0; i < nodes.Count; i++)         {             yield return nodes[i];         }     }      #endregion      #region INotifyCollectionChanged Members      public event NotifyCollectionChangedEventHandler CollectionChanged;      #endregion } 

Regards

  • 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. 2026-05-11T14:35:30+00:00Added an answer on May 11, 2026 at 2:35 pm

    Is there any reason you can’t use CompositeCollection?

    The reason the exception is being thrown is because you’re not translating the indexes of the inner collections to the outer. You’re just passing the exact same event args to the outer event (on MergedCollection), which is why WPF doesn’t find the items where the index is telling it to find them.

    You use a CompositeCollection like so:

    <ListBox>   <ListBox.Resources>     <CollectionViewSource x:Key='DogCollection' Source='{Binding Dogs}'/>     <CollectionViewSource x:Key='CatCollection' Source='{Binding Cats}'/>   </ListBox.Resources>   <ListBox.ItemsSource>     <CompositeCollection>       <CollectionContainer Collection='{Binding Source={StaticResource DogCollection}}'/>       <CollectionContainer Collection='{Binding Source={StaticResource CatCollection}}'/>     </CompositeCollection>    </ListBox.ItemsSource>    <!-- ... --> </ListBox> 

    For details, see this answer.

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

Sidebar

Related Questions

I have two classes (MVC view model) which inherits from one abstract base class.
I have two lists and I need to compare them and only return a
I have a form and two custom UserControl that I made myself. one control
I have two listviews, one for Images and one for Tags, which have a
Have two actionsheet buttons and one modalviewcontroller on mainviewcontroller in application. Now for two
I have an ObservableCollection<Object> that contains two different types. I want to bind this
I have a WPF program with two listviews which display information from two different
Is that even possible? I have two ObservableCollections. I want to bind and populate
I have two lists (ObservableCollections) of following class: public class Data { public string
I have two projects. First one is Wpf Project (FrameWork 3.5) with next interface:

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.