Groups | Blog | Home
all groups > asp.net building controls > january 2004 >

asp.net building controls : Why is the PropertyDescriptor's GetValue method called multiple times when selecting the descriptor into the PropertyGrid?


mark belles
1/21/2004 12:06:07 PM
i have a scenario in which i am using a ICustomTypeDescriptor in combination with an inherited PropertyDescriptor class to display information about an object using the PropertyGrid provided with .NET. I'm am using C#, and have noticed that the GetValue method which is overridden in my PropertyDescriptor class fires multiple times when the descriptor is placed into the SelectedObject property of the .NET PropertyGrid.

My 3 Questions are as follows...
Has anyone else noticed behavior like this?
Why does this occur?
How do I prevent it?

John Saunders
1/22/2004 2:49:37 PM
[quoted text, click to view]
combination with an inherited PropertyDescriptor class to display
information about an object using the PropertyGrid provided with .NET. I'm
am using C#, and have noticed that the GetValue method which is overridden
in my PropertyDescriptor class fires multiple times when the descriptor is
placed into the SelectedObject property of the .NET PropertyGrid.
[quoted text, click to view]

I have no answer, but I have a question for you: why do you need to prevent
it? Surely GetValue should be idempotent...
--
John Saunders
John.Saunders at SurfControl.com

mark belles
1/22/2004 11:26:05 PM
why do i need to prevent it? it just seems terribly inefficient to watch the grid call into the descriptor so many times. i would think that once before drawing, and then perhaps again after changes to a property, assuming you raised the event using the change service. even displaying a single property in the grid, the getvalue method is called really frequently. usually twice everytime the thing paints, or before a UITypeEditor is shown. lol, so all in all it works yes, just bothers me and i want to know why?

it's like if i had a control that fired the paint event several times in succession for no apparent reason. Would that bother you, or at least strike an inquisitive bone so that you might have to ask? lol, anyways, it's apparently nothing i can control, so i'm not really worried, i'd still like to know tho.
John Saunders
1/23/2004 1:25:48 PM
[quoted text, click to view]
the grid call into the descriptor so many times. i would think that once
before drawing, and then perhaps again after changes to a property, assuming
you raised the event using the change service. even displaying a single
property in the grid, the getvalue method is called really frequently.
usually twice everytime the thing paints, or before a UITypeEditor is shown.
lol, so all in all it works yes, just bothers me and i want to know why?
[quoted text, click to view]
succession for no apparent reason. Would that bother you, or at least strike
an inquisitive bone so that you might have to ask? lol, anyways, it's
apparently nothing i can control, so i'm not really worried, i'd still like
to know tho.


Actually, if I saw GetValue called multiple times, say, up to 10, or perhaps
up to 4*the number of objects in the property grid, then I'd assume there
was some reason for it that I simply didn't understand.

If I saw it called, say, 100*the number of objects, I'd wonder if it was a
bug.
--
John Saunders
John.Saunders at SurfControl.com

mark belles
1/23/2004 1:26:06 PM
i agree totally on the number of times called theory. i've already tried to figure out if it was related to the number of things i was showing, and it's not, it appears constant, give or take a call here and there. as far as i can tell, it's calling GetValue 7 times the first time the grid is loaded, this is up to the point i see the control, tracing with spy++ the first time until after the first paint message. it doesn't matter if i have 1 propertydescriptor or 50 in the grid, it's 7 calls for each. and then depending on the type of the property and uitypeeditor attached, anywhere from 2 to 6 calls again until after the editor is closed.

AddThis Social Bookmark Button