Stefan said:
Gabriel said:
private void MoveSplitter(PropertyGrid propertyGrid, int x)
{
object propertyGridView =
typeof(PropertyGrid).InvokeMember("gridView", BindingFlags.GetField |
BindingFlags.NonPublic | BindingFlags.Instance, null, propertyGrid, null);
propertyGridView.GetType().InvokeMember("MoveSplitterTo",
BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Instance,
null, propertyGridView, new object[] { x });
}
Eg:
MoveSplitter(myPropertyGrid, 100);
Hello, i tried this, but it doesn't work.
The Splitter always moves, but always to the same location.
I tried to pass values for x from -1000 to 1000, but it doesn't
have any effect.
My PropertyGrid has no categories, no help, no toolbar, just a few
properties. And I want to move the splitter
Any Ideas? .NET 2.0 ?
Well b****r me!
I've just posted a "How do I do that" question, and you bring this
ancient thread to the top by replying to it!
Since my post, I've found that those nice people at NDoc have written a
class called "RuntimePropertyGrid" with (among other things) :
/// <summary>
/// Gets or sets the width of the label.
/// </summary>
/// <value></value>
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public int LabelWidth
{
get
{
Type type = this.GetType().BaseType;
BindingFlags flags = BindingFlags.Instance | BindingFlags.Public |
BindingFlags.NonPublic;
FieldInfo field = type.GetField("gridView", flags);
object gridView = field.GetValue(this);
type = gridView.GetType();
PropertyInfo prop = type.GetProperty("InternalLabelWidth", flags);
object InternalLabelWidth =
prop.GetValue(gridView,BindingFlags.GetProperty,null,null,null);
return (int)InternalLabelWidth;
}
set
{
Type type = this.GetType().BaseType;
BindingFlags flags = BindingFlags.Instance | BindingFlags.Public |
BindingFlags.NonPublic;
FieldInfo field = type.GetField("gridView", flags);
object gridView = field.GetValue(this);
type = gridView.GetType();
MethodInfo method = type.GetMethod("MoveSplitterTo",flags);
method.Invoke(gridView,new Object[]{value});
}
}
It looks very similar, but I don't know if it is different enough to
make it work again.