Reputation: 10284
I have a Windows form (.NET 3.5) that contains a propertygrid control. The propertygrid control gets refreshed periodically do display any changes that may have occurred in the class which it represents. I want the refresh to only occur if the user is not currently editing a property in the grid. Is there a way to detect if the user is currently editing a control?
Upvotes: 4
Views: 1273
Reputation: 41
Yes - it's a little hacky but you can find out which subcontrol of the property grid is active, and make an educated guess based on what it is. The following seems to work:
bool isEditing = (propertyGrid.ActiveControl.GetType().Name != "PropertyGridView");
Upvotes: 4
Reputation: 43
You could hook up the OnLostFocus event. This way, the control would only get updated once it no longer had focus.
protected virtual void OnLostFocus( EventArgs e)
Upvotes: 0
Reputation: 128307
There probably is, but might I recommend having your type implement INotifyPropertyChanged
instead of refreshing the grid on a timer? This way you would never have to call Refresh
yourself; the display would automatically update the value displayed for each property whenever that property changed.
Of course, if your type has tons of properties, or if you're using your grid to dynamically display objects of many different types, this suggestion may not be practical. It's just a thought.
Upvotes: 1
Reputation: 39833
This is a fairly complex problem. I'd suggest a two fold approach:
If the control hasn't been modified within a certain threshold and has focus, or if the control doesn't have focus, I'd consider that to be sufficient to determine that it is not currently being edited.
Upvotes: 0