Propertygrid changes not picked up when using menu shortcut for saving
Posted
by
Ebbe
on Stack Overflow
See other posts from Stack Overflow
or by Ebbe
Published on 2011-02-10T12:59:43Z
Indexed on
2011/02/12
15:25 UTC
Read the original article
Hit count: 347
winforms
|propertygrid
I am trying to implement a simple windows forms application, where the user can edit instances of a simple Person class. The application makes use of the standard propertygrid, assigning instances of the Person class to the SelectedObject property of the propertygrid. When the user clicks the menu item Save, the application gets the selected item from the propertygrid and saves it. This works fine.
However, if a shortcut such as ctrl+S, assigned to the menu item, is used for saving the SelectedObject of the propertygrid, then the changes are not picked up. It appears to be related to the fact that the properties of the Person object are not updated unless the field in the propertygrid looses focus, and the ctrl+S shortcut doesn’t take away focus from fields in the propertygrid.
Other developers, such as Mark Gilbert, have solved this issue by forcing away focus from the propertygrid, but this seems to be a bit of a hack, especially since it would be nice to keep the focus at the field. The Visual Studio developers apparently got it right, but I haven’t figured out how.
© Stack Overflow or respective owner