views:

31

answers:

3

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?

A: 

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.

David Pfeffer
A: 

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.

Dan Tao
A: 

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)
matt.schechtman