I have a scenario where I am binding an object to my grid that contains a property that is another object. Then I am adding the second object's properties to the grid as unbound columns. Something like this:
Object1.ID
Object1.Object2
Object1.Name
Object2.State
Object2.City
So, for the above case my grid would have bound columns of ID and Name. It would also have unbound columns of State and City.
When the underlying object (Object1) is changed, the grid automatically becomes aware of this and my cell text us updated with the new value (like if I change the Name property). However, if the Object2 property of Object1 is changed... like changing the value of the "State" property, the grid will not update with the new value. I am thinking this is because I made State an unbound column. That makes sense to me.
My question is what event can I subscribe to in order to know when to refresh my unbound columns? I am using a binding source with my grid, so I thought I could listen for the ListChanged event or something. This did not fire when my property changed though. How does the bound column know to update when I make that change there?
Thanks!
Steve
You can add the properties in Object1 like:
public string State
{
get { return Object2.State;}
set { Objetc2.State = value;}
}
and let the grid do the rest...
Thanks for the reply Amiram! That is a neat idea that you have. However, that would break our object model and our architect would not like that. :) It would not make sense for Object1 to have a State property directly off of it. While the would solve my problem with the grid, it would make things confusing in other areas of the code where the objects are used.
Thanks,
So how about making a private class in the form class that has all those properties? It won't be seen from anywhere.