Hi,
I have a BindingList<T> collection and I am adding concrete object T in to
the binding list. Before adding them, I want to verify if object with same
data exist in the collection. When I use Binding list’s Contain method to
check if object exist in the collection, it always returns false. Is there a
way to achieve this? I have tried implementing IComparable interface on my
concrete class, but getting same result.
Code sample:
BindingList<User> uBL=new BindingList<User>();
User u=new User();
u.FirstName=”TTT”;
u.LastName=”CCC”;
if (! uBL.Contains(u)) //this always returns false
{
uBL.Add(u)
}
Public class User{
Public string FirstName=string.empty;
Public string LastName=string.empty;
Public User(){}
}
Thanks
Hiten
Ben Voigt - 03 May 2006 16:15 GMT
> Hi,
>
[quoted text clipped - 5 lines]
> way to achieve this? I have tried implementing IComparable interface on my
> concrete class, but getting same result.
IComparable is needed for sorting only, you want IEquatable and
IEquatable<T> so that referential identity is not used for the search.
> Code sample:
>
[quoted text clipped - 18 lines]
> Thanks
> Hiten