all groups > dotnet windows forms databinding > july 2007 >
You're in the

dotnet windows forms databinding

group:

Binding to PropertyGrid - SelectedObjectsChanged event not raised...



Binding to PropertyGrid - SelectedObjectsChanged event not raised... Andrew Brook
7/13/2007 12:00:00 AM
dotnet windows forms databinding: Hi Everyone,

I've databound the SelectedObject property of a PropertyGrid to a list of
objects that i have. When i select different objects the data appears fine
in my PropertyGrid. However, I want to perform some checking on the object
each time it changes. Because I had bound the data to the SelectedObject
property, I assumed the property would get called... however it only get
called once early on in my program and it never hits my breakpoints again.
To clarify this, any time the selected object of a PropertyGrid changes, I
would normally expect the SelectedObjectsChanged event to get raised, but it
doesn't.

Can anyone explain this behaviour? :)

thanks for reading,
Andrew Brook


Re: Binding to PropertyGrid - SelectedObjectsChanged event not raised... Marc Gravell
7/13/2007 12:00:00 AM
SelectedObjectsChanged is called when you set the SelectedObject
property (or SelectedObjects property if browsing the common
properties for muiltiple objects) to a different value - not when
something /on/ the selected object changes.

When you talk about your breakpoint, how do you mean? The assignment
step will not get repeated unless you deliberately invoke it - i.e.
with
theGrid.SelectedObject = someClass.SomeProperty;
the someClass.SomeProperty property is executed once (only) and the
returned value is passed to theGrid.SelectedObject; there is no
further liasing between thrGrid.SelectedObject and
someClass.SomeProperty (in either direction) unless you deliberately
code it that way by watching for change notifications.

Can you explain more about what you want to do? It sounds like the
list would have to perform this checking via notifications...

Marc

Re: Binding to PropertyGrid - SelectedObjectsChanged event not raised... Andrew Brook
7/13/2007 12:00:00 AM
Hi Marc - thanks for the response.

To clarify further my situation, I have a list of records in a datagrid
bound to a BindingList of custom business objects. Only a small number of
the possible properties of the business objects are shown in the datagrid.
The intention is that if a user wants to see more detail for that row, they
click on it and a PropertyGrid appears showing all the available properties
of the object. This works as correctly. When my data is loaded initially I
add a binding as follows

pgPropertyGrid1.DataBindings.Add("SelectedObject", this.BindingContext[d],
"Current");

However, in some instances, I don't want to show the full properties of a
row in the PropertyGrid. My plan therefor was to handle the
SelectedObjectsChanged event of the PropertyGrid and at that point check my
criteria as to whether the PropertyGrid should be enabled/disabled/visible
etc.

[quoted text, click to view]

It's a shame this is the case - how would you suggest I check for
notifications?

thanks
Andrew


[quoted text, click to view]

Re: Binding to PropertyGrid - SelectedObjectsChanged event not raised... Marc Gravell
7/13/2007 11:58:38 AM
Well, you could keep it simple, and do the hooking manually - i.e.
handle CurrentChanged (on the binding source/context) and set
SelectedObject, Enabled, and Visisble as appropriate

Marc

Re: Binding to PropertyGrid - SelectedObjectsChanged event not raised... Andrew Brook
7/13/2007 12:30:12 PM
Thanks Marc,

I added the event hookup and I can now tell when the object changes.
Although, it doesn't raise the event the very first time the object is
assigned, I can experiment a little to work out why that is... :)

ta
Andrew

[quoted text, click to view]

AddThis Social Bookmark Button