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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:23:11+00:00 2026-05-13T23:23:11+00:00

I’m working on a bigger project atm, but I made this simple example to

  • 0

I’m working on a bigger project atm, but I made this simple example to show you what happens..

using System.Collections.Generic;
using System.Windows;
namespace txt
{
    public partial class MainWindow
    {
        public MainWindow()
        {
            InitializeComponent();
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            var obsLst = new List<Info> { new Info { name = "asd" }, new Info { name = "asd" }, new Info { name = "asd" }, new Info { name = "asd" } };
            var temp = new List<Info>();
            for (var i = 1; i <= 3; i++)
            {
                temp.Add(obsLst[0]); //I add 3 of the same item from obsLst to temp
            }
            lst.DataContext = temp; //lst = ListBox
        }
    }
    public class Info
    {
        public string name { get; set; }
    }
}

The ListBox ItemsSource is set to {Binding}..

When I start the application I get 3 txt.Info objects displayed and if I click any of them, 2 or even all of them get selected aswell. From my understanding the problem relies in the fact that the listbox selector cannot differentiate between the items and therefor doesn’t know which one I selected.

Here’s a picture of what it looks like..
alt text

I only clicked on the second txt.Info item.

I found a solution where someone said that I have to specify the DisplayMemberPath, but I can’t really do that in the other project because I have a datatemplate for the object.

Any ideas on how I could fix this would be great..

Thx in advance.

EDIT 1:
this works but it’s not nice..

using System.Collections.Generic;
using System.Windows;

namespace txt
{
    public partial class MainWindow
    {
        public MainWindow()
        {
            InitializeComponent();
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            var obsLst = new List<Info> { new Info { name = "asd" }, new Info { name = "asd" }, new Info { name = "asd" }, new Info { name = "asd" } };
            var temp = new List<Container>();
            for (var i = 1; i <= 3; i++)
            {
                var t = new Container();
                t.obj = obsLst[0];
                temp.Add(t);
            }
            lst.DataContext = temp;
        }
    }
    public class Info
    {
        public string name { get; set; }
    }

    public class Container
    {
        public Info obj { get; set; }
    }
}

In this case you need to set DisplayMemberPath=”obj”

Assigning an ID to the object, doesn’t work..

using System;
using System.Collections.Generic;
using System.Windows;

namespace txt
{
    public partial class MainWindow
    {
        public MainWindow()
        {
            InitializeComponent();
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            var rand = new Random();
            var obsLst = new List<Info> { new Info { name = "asd" }, new Info { name = "asd" }, new Info { name = "asd" }, new Info { name = "asd" } };
            var temp = new List<Info>();
            for (var i = 1; i <= 3; i++)
            {
                obsLst[0].id = rand.Next(10000);
                temp.Add(obsLst[0]);
            }
            lst.DataContext = temp;
        }
    }
    public class Info
    {
        public string name { get; set; }
        public int id { get; set; }
    }
}
  • 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-13T23:23:12+00:00Added an answer on May 13, 2026 at 11:23 pm

    I had this problem too a while ago, i fixed it by adding the id # to the item so they’re always different.

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

Sidebar

Related Questions

Seemingly simple, but I cannot find anything relevant on the web. What is the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I want use html5's new tag to play a wav file (currently only supported
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

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.