Reputation: 39700
I'm building an app where I show data in a tree view, and when a user double-clicks on an element in the tree view, the node they clicked on is replaced with an editable version of the node. The way different nodes are edited varies greatly, so using the built-in ability to change the text of the node is not acceptable. I instead need to use a property grid and define [Editor] attributes.
The only problem is that the property grid shows two columns: One with the name of the property, and the other with its value. I need to only show the value column (the part the user can edit). Is there some way to remove the first column, or use the property grid's functionality in a different, custom class that only shows one column?
Upvotes: 3
Views: 1605
Reputation: 139167
This 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:
Hope this helps!
Upvotes: 3