user153923
user153923

Reputation:

PropertyGrid AutoSelect Property Value

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.

Upvotes: 1

Views: 1007

Answers (1)

LarsTech
LarsTech

Reputation: 81610

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();
  }
}

Upvotes: 1

Related Questions