1

It was a looooooong time since I did a winform desktop application in .Net and I wanted to do some selections based on listboxes. The problem is that any item I select in a listbox also changes the selection of the other listboxes bound to the same data. I tried to find people who have had the same problem but couldn't find any so I guess I'm doing something fundamentally wrong. Anyone have any hints? See below for the basic code.

Class for handling data (to which I later use as DataSource in listboxes).

public class Registry
{
    public ICollection<Data.Vertice> Vertices { get; set; } = new List<Data.Vertice>();
}

How I set the data source to a listbox

listBox1.DataSource = null;
listBox1.DataSource = _registry.Vertices;
listBox1.DisplayMember = "Title";
Sandman
  • 795
  • 7
  • 16
  • When you move `Current`, all Controls bound to the same source of data are synchronized. Isn't that expected? What do you want to happen instead? That Controls other than the one you're currently interacting with lose synchronization and show something else? What else? -- You can always suspend their binding, but... – Jimi Jul 10 '22 at 11:55
  • If you want the same source of values, but different selections you need for each list box it's own BindingSource. All BindingSources can use the same list but each will manage it's own selected item. – Oliver Jul 10 '22 at 12:49
  • So using the same DataSource also creates some common sync of selected item between all the listboxes? – Sandman Jul 10 '22 at 13:35
  • 1
    This is already answered here for ComboBox: [Bind multiple ComboBox to a single List - Issue: When I select an item, all combo boxes change](https://stackoverflow.com/a/35865838/3110834) – Reza Aghaei Jul 10 '22 at 13:57

1 Answers1

0

Reza Aghai Solved the problem by finding a a post which I had missed in my search.

Basically a single BindingManagerBase is created and reused if you use the same DataSource. This can be solved by creating a new DataSource by for example doing the following:

DataSource = yourList.ToList()
Sandman
  • 795
  • 7
  • 16