views:

440

answers:

1

I'm working on a UserControl that consists of a bunch of ComboBoxes arranged horizontally across the top of the control in a flowlayoutpanel, and a datagridview directly below the flowlayoutpanel that takes up all remaining space on the control. I need to be able to hide all the dropdowns easily, so I have a SplitContainer with Orientation == Horizontal, with the flowlayoutpanel in SplitContainer.Panel1, and the datagridview in SplitContainer.Panel2.

The control hierarchy is as follows:

SplitContainer1
    SplitContainer1.Panel1
        FlowLayoutPanel1
            ComboBox1
            ComboBox2
            ComboBox3
    SplitContainer1.Panel2
        DataGridView1

Since the flowlayoutpanel is oriented horizontally and horizontal space is limited, the flowlayoutpanel's WrapContents property is True, so that the dropdowns wrap down to the next row when the control is made too narrow to fit all the dropdowns in one row.

The problem I'm having is that when the flowlayoutpanel wraps its contents down onto the next row, its Height property does not change accordingly. The wrapped rows of the flowlayoutpanel are clipped, and don't force the splitcontainer panel to grow in height accordingly. I've tried to handle the FlowLayoutPanel.Resize event to grow and shrink the SPlitContainer.SplitterDistance property to accommodate the wrapped contents, but the FlowLayoutPanel.Height property does not change when contents are wrapped. I'm stumped. Is the FlowLayoutPanel broken? How can I resize the FlowLayoutPanel's parent container if FlowLayoutPanel.Height always remains the same, regardless of content wrapping?

Thanks

+1  A: 

It seems like you're making this a little too complicated for what you need. You can use the built-in docking to accomplish what you want without using the SplitContainer. Set up your form like this instead:

FlowLayoutPanel1 (Autosizse = true, Dock = Top)
  ComboBox1
  ComboBox2
  ComboBox3
DataGridView1 (Dock = Fill)

Then when you want to hide FlowLayoutPanel1 you can just toggle the Visible property to hide/show it.

Shawn Steward
Brilliant! This worked perfectly!
echo