PropertyGrid selection bug when properties have identical DisplayName?
See the question and my original answer on StackOverflowI don't think it's a bug, it's probably a feature (with side effects :-). You can check the property grid source on Microsoft site. The relevant portion seems this in GridEntry.cs code:
public override bool Equals(object obj) {
if (NonParentEquals(obj)) {
return((GridEntry)obj).ParentGridEntry == this.ParentGridEntry;
}
return false;
}
internal virtual bool NonParentEquals(object obj) {
if (obj == this) return true;
if (obj == null) return false;
if (!(obj is GridEntry)) return false;
GridEntry pe = (GridEntry)obj;
return pe.PropertyLabel.Equals(this.PropertyLabel) &&
pe.PropertyType.Equals(this.PropertyType) && pe.PropertyDepth == this.PropertyDepth;
}
As you see, it's the PropertyLabel which is used. If you follow the code a bit more, the label will ultimately use the property's DisplayName (or the name if the DisplayName attribute is not defined).