I have a PropertyGrid
whose selected object contains multiple properties with [DisplayName]
s of "Speed", all in different categories (the real property names in the code are of course all unique). I've noticed that if I have (for example) Speed #3 selected and PropertyGrid.Refresh()
is called, the selection will automatically move to Speed #1. What's more, the value of Speed #3 will sometimes be shown next to Speed #1 too. The situation resolves itself as soon as I click the grid and change the selection, but it's obviously not desired behavior.
I am currently hacking around this by adding different numbers of \t
characters to the DisplayName
s to make them all unique. This is an acceptable workaround since the tab characters aren't actually rendered, but I'd of course prefer not to have to do it.
Is there a rule that all DisplayName
s must be unique or is this a bug in PropertyGrid
?
Update: Since someone's bound to ask for a code sample, stick one of these in a PropertyGrid
and then call Refresh()
on it from a timer every two seconds or so:
class Demo
{
[Category("Cat1")]
[DisplayName("Speed")]
public int Speed1 { get; set; }
[Category("Cat2")]
[DisplayName("Speed")]
public int Speed2 { get; set; }
[Category("Cat3")]
[DisplayName("Speed")]
public int Speed3 { get; set; }
}