C# PropertyGrid - Check if a value is currently beeing edited
See the question and my original answer on StackOverflowI don't think there is any official way. However the following piece of code can detect when a grid entry is opened using the builtin text box editor, or the dropdown editor. It does not detect when an entry is opened using the small '...' edit button.
public static bool IsInEditMode(PropertyGrid grid)
{
if (grid == null)
throw new ArgumentNullException("grid");
Control gridView = (Control)grid.GetType().GetField("gridView", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(grid);
Control edit = (Control)gridView.GetType().GetField("edit", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(gridView);
Control dropDownHolder = (Control)gridView.GetType().GetField("dropDownHolder", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(gridView);
return ((edit != null) && (edit.Visible & edit.Focused)) || ((dropDownHolder != null) && (dropDownHolder.Visible));
}
Of course, since it's based on the grid internal structure, it may change in the future, so, use at your own risk.