I’ve got a Windows Forms application with two ListBox controls on the same form. They both have their SelectionMode set to ‘MultiExtended’.
When I change the selection of one the selection of the other changes.
Now I thought I’d done something stupid with my SelectedIndexChanged handlers so I removed them and re-wrote them from scratch, and got the problem.
So I created a brand new WinForms app and dragged two ListBoxes onto the forms surface.
In the constructor I populated them both with the following.
List<Thing> data = new List<Thing>(); for ( int i = 0; i < 50; i++ ) { Thing temp = new Thing(); temp.Letters = 'abc ' + i.ToString(); temp.Id = i; data.Add(temp); } listBox1.DataSource = data; listBox1.DisplayMember = 'Letters'; listBox1.ValueMember = 'Id'; List<Thing> data2 = new List<Thing>(); for ( int i = 0; i < 50; i++ ) { Thing temp = new Thing(); temp.Letters = 'abc ' + i.ToString(); temp.Id = i; data2.Add(temp); } listBox2.DataSource = data2; listBox2.DisplayMember = 'Letters'; listBox2.ValueMember = 'Id';
And then I built and ran the app.
Started selecting some values to see if the symptoms were present. And they were!
This is literally all the code I added to the form,I had not added any event handlers, I have tried it with the SelectionMode set to ‘One’ and ‘MultiExtended’.
Can anyone give me a clue as to why this is happening.
Cheers
It isn’t the list that stores the current position – it is the
CurrencyManager. Any controls (with the sameBindingContext) with the same reference as aDataSourcewill share aCurrencyManager. By using different list instances you get differentCurrencyManagerinstances, and thus separate position.You could achieve the same simply by using
.ToList(), or creating a newList<T>with the same contents (as per your original post), or by assigning a newBindingContextto one of the controls: