Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / May 2006

Tip: Looking for answers? Try searching our database.

Contains method doesn't work on BindingList<T>

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Hiten - 03 May 2006 03:54 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.