开发者

Winforms -- multi select dropdown list

I'm shopping around for a dropdown list control that allows me to select multiple items. Something akin to the CheckedListbox, but in dropdown list form (I don't want it to take up开发者_如何学编程 a big chunk of the screen). At this point I'm pretty convinced there is no such control built-in .NET.

Note this is Winforms, not ASP.NET. Any suggestions?


Check out this project on CodeProject:

  • CheckBox ComboBox Extending the ComboBox Class and Its Items


There is yet another fix:

The above solution is correct to fix the first issue, where it required two clicks to enter the list of checkboxes, however, this introduces a new issue when you click the control to exit it, it retains focus and you must double click to go to another control. I was able to fix this with the following code:

In CheckBoxComboBox.cs add the following override:

    protected override void OnClick(EventArgs e)
    {
        base.OnClick(e);
        this.Parent.Focus();
    }

With the answer from Rob P. and this answer, it will not hold focus on either click event.


Here is another solution which works better for me from a UI perspective, I find the UI more refined and code easier to use/understand:

https://www.codeproject.com/Articles/31105/A-ComboBox-with-a-CheckedListBox-as-a-Dropdown

Note there are a couple of fixes required to avoid the double click issue which can be found in the comments. Quoting from Herrpel (9-May-17)

Add this to the outer class CheckedComboBox

protected override void OnMouseDown(MouseEventArgs e)
{
    base.OnMouseDown(e);
    DroppedDown = false;
}

and for the Windows 10 losing focus on closing the box issue, change the code in CloseDropdown: from

ccbParent.Focus();
this.Hide();

to

ccbParent.BeginInvoke(new MethodInvoker(() => this.Hide()));


You should Show again the dropdown Form, because the code below closes it.

The code that Works is:

protected override void OnClick(EventArgs e)
{
        base.OnClick(e);
        this.Parent.Focus();
        this.dropDown.Show(this);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜