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 / Windows Forms / WinForm General / March 2007

Tip: Looking for answers? Try searching our database.

Binding custom objects

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Alla - 14 Mar 2007 07:30 GMT
Hi,

I got a problem with binding custom objects to the controls. Let's say we
have 2 objects: obj1 and obj2. In my case DataGrid column is bound to the
obj1 and ComboBox in that column is bound to the collection of obj2 and has
its ValueMember as Guid and DisplayMember as string from the obj2. Inside
the obj1, I got Guid as a property. Obj1.Guid should match with obj2.Guid in
order to correctly display the value in the grid column. However it does not
display any value as I think it is trying to match obj1 with the obj2.Guid
instead of obj1.Guid with obj2.Guid. At the moment I am overriding Equals()
and ToString() methods and it works however it's probably a better way to do
it.

Thanks a lot
Simon Tamman - 14 Mar 2007 15:06 GMT
I do the same thing. Ignore DisplayMember and ValueMember and override
ToString().

This means the comparison is always:

instanceX == instanceY

Obviously if you override equals to use the Guid as a comparison the
comparison will work with identical guids even if the object's memory
addresses are different.

I "think" DisplayMember and ValueMember are mainly for those working with
DataSets and Tables.

HTH

Simon

> Hi,
>
[quoted text clipped - 10 lines]
>
> Thanks a lot
Simon Tamman - 14 Mar 2007 15:06 GMT
If there is a better way then i'd like to know it too as this is what I do
as well.
I don't usually override equals as I rely on the objects having the same
address in memory but I never use DisplayMember or ValueMember. I think
those properties  are mainly for DataSet and DataTable users.

> Hi,
>
[quoted text clipped - 10 lines]
>
> Thanks a lot

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.