How to make a Stripped Down PropertyGrid
See the question and my original answer on StackOverflowThis is not possible without hacking the property grid. Here is a code that can change the label column's width:
public static void SetLabelColumnWidth(PropertyGrid grid, int width)
{
if (grid == null)
throw new ArgumentNullException("grid");
// get the grid view
Control view = (Control)grid.GetType().GetField("gridView", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(grid);
// set label width
FieldInfo fi = view.GetType().GetField("labelWidth", BindingFlags.Instance | BindingFlags.NonPublic);
fi.SetValue(view, width);
// refresh
view.Invalidate();
}
public static void ResetLabelColumnWidth(PropertyGrid grid)
{
SetLabelColumnWidth(grid, -1);
}
Use it just like this to remove the label column:
SetLabelColumnWidth(propertyGrid1, 0);
The reset function restores the label column.
Of course, it's a hack so it may not work in the future. There are also issues:
- The v-splitter cursor is shown when the mouse moves to the grid's left side, and the user can select it and reset the label column if he clicks.
- Some grid actions may also restore the label column (like using the property grid toolbar).
Hope this helps!