Why is the PropertyDescriptor's GetValue method called multiple times when selecting the descriptor

M

mark belles

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?

I will be happy to provide example code if anyone needs to see it.
 
J

John Saunders

mark belles said:
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?

I have no answer, but I have a question for you: why do you need to prevent
it? Surely GetValue should be idempotent...
 
M

mark belles

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.
 
J

John Saunders

mark belles said:
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.


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.
 
M

mark belles

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.

obviously this is by design, and obviously i don't get why, which is why i'm asking on here. lol odd eh?
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top