Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

Binding to HashSet

$
0
0

Hi,

We're trying to data bind to a HashSet but found that it isn't working as expected.

var list = new HashSet<string>();
            list.Add("David");
            list.Add("Peter");
            list.Add("Paul");
            list.Add("Mary");
            list.Add("Gillian");

var bindingSource = new BindingSource {DataSource = list};

bindingSource.RemoveAt(0);

Debug.Assert(list.Count == 4); // Fails as count = 5

           

If the collection is an IList<>, then as soon as an item is removed from the binding source then this is reflected in the underlying collection. However, with a HashSet<> collection, the underlying collection doesn't get updated.

Why do they not behave the same?


Dave


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>