James_Steven

I created a search form in a panel, to be placed in forms: A textbox and a button on top, and a datagridview docked to bottom.

I add this panel to my form, and set dock to fill.

Then the problem occurs: If the form i add this panel to is higher than the panel, the datagridview will just remain the same size, and stay at the bottom, while the textbox and the button is at top, making a big empty space in the middle.

Like this:

[TEXTBOX] [BUTTON]

-----------------------------
| Dataridview area |
-----------------------------

How can i make the datagrid automaticly adjust it's own size, to fill the empty space What i basicly want is to spike the top of the datagrid to right underneith the textbox and button, and whenever the form height is resized, the bottom of the gridarea will adjust itself to the bottom of the form. Like this:

[TEXTBOX] [BUTTON]
-----------------------------
| Dataridview area |
| |
| |
-----------------------------



Re: Windows Forms General Question about docking a control in a panel

Richard Guion

You can use multiple panels inside a SplitContainer to achieve the correct behavior.

PanelContainer: This is a SplitContainer control. Dock should be set to fill, Orientation should be Horizontal. This contains two sub panels, Panel 1 (top) and Panel 2 (bottom).

In Panel 1, add your textbox and search button. The SplitContainer FixedPanel property should be set to Panel1, so that this area will remain the same size, allowing the DataGridView to expand correctly.

In Panel 2, add your datagrid view. Dock it in the parent container, Dock should automatically be set to Fill.

Now when the form gets resized, your DataGridView will adjust itself correctly.






Re: Windows Forms General Question about docking a control in a panel

Karthik Krishnaswami

You can try something simple by doing this-

Instead of docking to bottom,design the datagrid in the designer such that it is at 0 from left edge and right edge.(i.e. do the docking by hand).Then make sure that the bottom edge is flush with the bottom edge of the panel.Once you have done this,set the AnchorStyle of the datagridView to Top,Bottom,Left,Right.

Hope this helps.





Re: Windows Forms General Question about docking a control in a panel

James_Steven

Thanks for your replies! I got it working with the splitcontainer, but i'll try your solution too Karthik



Re: Windows Forms General Question about docking a control in a panel

theblueeyz

Sometimes you'll want to do the docking by hand, which I do when I've already used alot of containers. This is because the performance of the built-in containers isn't spectacular. The split container is generally ok, but the table layout panel.. ugh, only use that thing when you have to, because it is very slow.  The FlowLayoutPanel is where this breaks down, though, because its behavior can't be reproduced using built-in docking and anchoring methods.  Its behavior is entirely custom.

Anywho just a thought on using the resizing containers.