Programmatically resize a column in a Windows Forms property grid control

Using the standard Microsoft .NET 2.0 WinForms PropertyGridControl control, I was looking for a way to set the size of the two columns (one for the labels, one for the values) so that I can control better how the values are displayed.

After some research with ILSpy on the .NET sources, I found a way to use with reflection. The following helper method can be used for this task:

Call the function and pass your PropertyGrid instance and width values between e.g. 10 and 90 to resize the first column to the given percentage value.

E.g.:

If you specify a too small or too large value, the PropertyGrid seems to use the minimum/maximum possible, based on your passed value.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">