I need the left column to be about 25% of the width and the right column to
be the remaining 75%.
Can this be done by setting a property in the property grid?
Thanks!
There is unfortunately no way to know the width of the label and value
columns and no way to set it. I found a hack that works at init time
when we know that the 2 columns have the same width. This is really a
hack ;)
Here is what I did:
In my Form_Load:
ActiveControl = propertyGrid2;
propertyGrid.Controls[2].GotFocus += new EventHandler(Form1_GotFocus);
The Form1_GotFocus code:
void Form1_GotFocus(object sender, EventArgs e)
{
int count = (int)((propertyGrid.Controls[2].Width - 16 -
SystemInformation.VerticalScrollBarWidth) * 0.25 / 3);
keybd_event(0x11 /*VK_CONTROL*/, 0x9d, 0, UIntPtr.Zero); // Ctrl
Press
for (int i = 0; i < count; i++)
{
keybd_event(0x25 /*VK_LEFT*/, 0x9e, 0, UIntPtr.Zero); // Left
arrow Press
keybd_event(0x25 /*VK_LEFT*/, 0x9e, 0x0002/*KEYEVENTF_KEYUP*/,
UIntPtr.Zero); // Left arrow Press Release
}
keybd_event(0x11 /*VK_CONTROL*/, 0x9d, 0x0002/*KEYEVENTF_KEYUP*/,
UIntPtr.Zero); // Ctrl Release
}
The keybd_event is defined as:
[DllImport("user32.dll")]
[CLSCompliant(false)]
public static extern void keybd_event(byte bVk, byte bScan, uint
dwFlags, UIntPtr dwExtraInfo);
I assumed there was a width of 16 for the first grayed column and that
the vertical scrollbar was here. I also harcoded your 25% for the label
column.
This hack works on the fact that if a user presses CTRL + left or right
arrow, the splitter bar will move 3 pixels in either directions.
Hope this helps and that you will be able to use this solution.
Best regards,
Nicolas Cadilhac @ VisualHint (http://www.visualhint.com)
Home of Smart PropertyGrid for .Net and MFC
Best regards,
Nicolas Cadilhac @ VisualHint (http://www.visualhint.com)
Home of Smart PropertyGrid for .Net and MFC
Best regards,
Nicolas Cadilhac @ VisualHint (http://www.visualhint.com)
Home of Smart PropertyGrid for .Net and MFC
I'll get to work on your snippet right away :)
Thanks!