Winforms — multi select dropdown list

后端 未结 4 1999
Happy的楠姐
Happy的楠姐 2020-12-24 02:47

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

相关标签:
4条回答
  • 2020-12-24 03:16

    Check out this project on CodeProject:

    • CheckBox ComboBox Extending the ComboBox Class and Its Items
    0 讨论(0)
  • 2020-12-24 03:16

    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.

    0 讨论(0)
  • 2020-12-24 03:24

    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()));
    
    0 讨论(0)
  • 2020-12-24 03:24

    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 讨论(0)
提交回复
热议问题