Propertygrid properties not selected when using menu shortcut to save

I am trying to implement a simple Windows forms application where a user can edit instances of a simple Person class. The application uses the standard propertygrid, assigning the SelectedObject property of the grid property to instances of the Person class. When the user clicks the Save menu item, the application retrieves the selected item from the property and saves it. It works great.

However, if a shortcut is used to save the SelectedObject property of the gridgrid, such as ctrl + S assigned to the menu item, no changes are accepted. It seems that this is due to the fact that the properties of the Person object are not updated if the field in the grid properties does not lose focus and ctrl + S shortcut does not remove the focus from the fields in the properties.

Other developers, such as Mark Gilbert, solved this problem by displacing focus from the Grid property, but this seemed to hack a bit, especially since it would be nice to keep focus on the field. Obviously, the developers of Visual Studio understood this, but I did not understand how to do this.
+3
source share
2 answers

You have two different approaches:

  • As Mark Gilbert and @ Tergiver explains, you can remove focus from the inplace control, which will capture a change in value before the menu command is displayed. Since you must do this from your OnSave handler, you put a grid dependency.

  • . PropertyGrid ProcessCmdKey. Ctrl + S, , base.ProcessCmdKey(). 1, ( , Ctrl + S) . , , .

...

0

PropertyGrid. (), .

0

Source: https://habr.com/ru/post/1791211/


All Articles