0

I am working with a SplitterPanel in winforms where on the right hand side I want a custom dropdown list control which displays a 2 columns dropdown list.

The problem is that with there being two columns I want to be able to have a larger dropdown list area than the actual dropdown, and therefore overlap the SplitterPanel if the list doesn't fit in the split area.

I have tried using .BringToFront();, however this does not work on the SplitterPanel and the control is hidden. I come from a web background where I would have used z-index for this but I am stumped with winforms. See below image of my issue.

Does anyone know how I can resolve this?

enter image description here

user3284707
  • 3,033
  • 3
  • 35
  • 69
  • Related: [How to set Z-order of a Control using WinForms](http://stackoverflow.com/questions/3213270/how-to-set-z-order-of-a-control-using-winforms) – stuartd Sep 22 '16 at 11:19
  • 1
    Most probably the problem is with the custom control you are using. Normally dropdown popup portions are not clipped. – Ivan Stoev Sep 22 '16 at 11:36
  • You are probably right, it is just a standard CheckedListBox which is brought up on screen to give the appearance of a dropdown list. When I drop one onto the page and put it half and half it goes behind the divider. Do you know any way to make that appear above the divider, the SetChildIndex does not seem to work. – user3284707 Sep 22 '16 at 12:00
  • Simply don't drop it onto splitter but keep it above it. Can you post the relevant code for showing it? – TaW Sep 22 '16 at 20:19
  • The z-index will determine which child controls sit higher and can overlap which others child controls. But it never helps when you want a (real) child overlap its own container. This never happens; and since the CheckedListBox is the child of the split panel it will never overlap it. – TaW Sep 23 '16 at 06:51
  • There are not many .NET controls in the toolbox that allows extending the window beyond the bounds of the parent. Doctoring the Z-order doesn't help, you still want to extend it beyond the bounds of the main window. There are two, the Form class and the ContextMenuStrip class. Do note that this is really a context menu, CMS already support checkboxes. Doctoring the dropdown list of a combobox [is common](https://code.msdn.microsoft.com/windowsdesktop/CheckedCombobox-Control-52dbdb37#content) but you probably don't want that either if the text property needs to be custom. Use CMS. – Hans Passant Sep 23 '16 at 08:26

2 Answers2

2

The z-index will determine which child controls sit higher and can overlap which others child controls. But it never helps when you want a (real as opposed to drop downs or menues) child overlap its own container. This never happens; and since the CheckedListBox is the child of the split panel it will never overlap it.

You will need to make the CheckedListBox sit not inside the splitter panel but in its Parent so the they are 'brethren'. Let's assume the SplitContainer sits in a TabPage tabPage8. Then you can show it fully by moving it to that tabPage:

moveCtlToTarget(tabPage8, checkedListBox1);

using this function.

void moveCtlToTarget(Control target, Control ctl)
{
    // get screen location of the control
    Point pt = ctl.PointToScreen(Point.Empty);
    // move to the same location relative to the target
    ctl.Location = target.PointToClient(pt);
    // add to the new controls collection
    ctl.Parent = target;
    // move all up
    ctl.BringToFront();
}

As I don't know how you create and show it, resetting it is up to you. Note that as it now is no longer in the split panel it will not move when you move the splitter..

You may want to do this only the first time and later align it with the ComboBox..

TaW
  • 53,122
  • 8
  • 69
  • 111
1

TaW's answer above helped my solve my issue. I modified it slightly for my situation where I moved the parameters into the method as I already had my checkbox control set as a property of the control and got the target by looping up the parents until I got to the top.

    private void moveCtlToTarget()
    {
        Control Target = Parent;
        while (Target.Parent != null)
            Target = Target.Parent;

        Point pt = CheckBox.PointToScreen(Point.Empty);
        CheckBox.Location = Target.PointToClient(pt);
        CheckBox.Parent = Target;
        CheckBox.BringToFront();
    }
user3284707
  • 3,033
  • 3
  • 35
  • 69