I am building a WPF app where a DataGrid
binds a HashSet
of Product
, and two Products
with the same ID are considered equal. A user is allowed to add new row to the DataGrid
to describe a new Product, and I'd like to notify the user if two rows have the same ID. But how do I detect that? The problem is that the DataGrid
binds to items
, which was created as
items = new ObservableCollection<Product>(new HashSet<Product>());
and the duplicate product is automatically inserted and never ends up in the items
(although it does show up on the DataGrid
, why?)
so in short, 2 questions:
- How to detect the duplicate at the time of insertion?
- Why does the duplicate shows up in DataGrid?