1

We use a PropertyGrid to store information about various GUI controls.

Currently, after dropping a new control onto the form, we next click the PropertyGrid, scroll to the field called Value and enter the value that will be displayed for that item.

I can handle the part where the PropertyGrid gets focus, and I can even cast the SelectedObject back to our base GuiControl object.

Obviously, Value is a public property of our GuiControl class.

I don't see a way to find the Value property on the PropertyGrid and set it to focus to receive text input.

The goal is to drop a control onto the form, have the PropertyGrid get focus, place the Cursor's Caret on the Value line, and then we can supply our input.

Is that possible? If so, please give me some idea on how to do that.

  • Think of Hot Keys. &F to select the File menu; &T to select Tools, etc. –  Jan 26 '16 at 22:18
  • Possible duplicate of [How to set selected item of property grid](http://stackoverflow.com/questions/24571817/how-to-set-selected-item-of-property-grid) – GuyVdN Jan 26 '16 at 22:27

1 Answers1

1

Try looping through the GridItems collection to find the Label that matches your property:

foreach (GridItem gi in propertyGrid1.SelectedGridItem.Parent.GridItems) {
  if (gi.Label == "Value") {
    propertyGrid1.Select();
    gi.Select();
  }
}
LarsTech
  • 80,625
  • 14
  • 153
  • 225
  • Yeah! That did it. Of course now I see that I can't actually write to `gi.Value` because it is read only. –  Jan 26 '16 at 22:36