Binding custom objects

A

Alla

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
 
S

Simon Tamman

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
 
S

Simon Tamman

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top