Discussion:
Using the PropertyGrid Control
(too old to reply)
Bill
2009-07-28 14:44:09 UTC
Permalink
In C#, I'm using a PropertyGrid control to display a custom class. It works
wonderfully, but I'm just wondering if anyone knows a way to specify the
width of each of the slider panels. It seems to split 50/50 by default.
I would like to have the left side (column containing the property names)
open with a width of about 25% by default.

Is this possible?

Thanks,
Bill
Morten Wennevik [C# MVP]
2009-08-12 06:17:01 UTC
Permalink
Hi Bill,

Yes you can, but to my knowledge only by using reflection. These methods
are not documented so they may change in the future. However, the
Windows.Forms development is now more or less stopped in favour of WPF so the
functionality is not likely to change.

The actual grid part is a PropertyGridView, which is a private field on the
PropertyGrid. The PropertyGridView has a private MoveSplitterTo method you
can use to move the splitter bar.

FieldInfo fi = typeof(PropertyGrid).GetField("gridView",
BindingFlags.Instance | BindingFlags.NonPublic);
object propertyGridView = fi.GetValue(propertyGrid1);

MethodInfo mi = propertyGridView.GetType().GetMethod("MoveSplitterTo",
BindingFlags.NonPublic | BindingFlags.Instance);
mi.Invoke(propertyGridView, new object[]{10});
--
Happy Coding!
Morten Wennevik [C# MVP]
Post by Bill
In C#, I'm using a PropertyGrid control to display a custom class. It works
wonderfully, but I'm just wondering if anyone knows a way to specify the
width of each of the slider panels. It seems to split 50/50 by default.
I would like to have the left side (column containing the property names)
open with a width of about 25% by default.
Is this possible?
Thanks,
Bill
Bill
2009-08-25 15:08:45 UTC
Permalink
Morten,

This work great. I just placed your code in the Layout event for the
PropertyGrid and the problem was solved.

Thanks for taking the time to solve this for me.

Bill
Post by Morten Wennevik [C# MVP]
Hi Bill,
Yes you can, but to my knowledge only by using reflection. These methods
are not documented so they may change in the future. However, the
Windows.Forms development is now more or less stopped in favour of WPF so the
functionality is not likely to change.
The actual grid part is a PropertyGridView, which is a private field on the
PropertyGrid. The PropertyGridView has a private MoveSplitterTo method you
can use to move the splitter bar.
FieldInfo fi = typeof(PropertyGrid).GetField("gridView",
BindingFlags.Instance | BindingFlags.NonPublic);
object propertyGridView = fi.GetValue(propertyGrid1);
MethodInfo mi = propertyGridView.GetType().GetMethod("MoveSplitterTo",
BindingFlags.NonPublic | BindingFlags.Instance);
mi.Invoke(propertyGridView, new object[]{10});
--
Happy Coding!
Morten Wennevik [C# MVP]
Post by Bill
In C#, I'm using a PropertyGrid control to display a custom class. It works
wonderfully, but I'm just wondering if anyone knows a way to specify the
width of each of the slider panels. It seems to split 50/50 by default.
I would like to have the left side (column containing the property names)
open with a width of about 25% by default.
Is this possible?
Thanks,
Bill
Loading...