1
votes

I have a combobox on a winform with dropdownstyle set to DropDownList.

When the user clicks anywhere on the combobox, its dropdownlist opens up. If I use any other dropdownstyle (DropDown or Simple) this is not the case, the combobox will only open up when the user clicks on the arrow on the right.

What I need is a combobox that has dropdownstyle set to DropDownList but still only opens its dropdown list when clicking on the arrow on the right, not when clicking anywhere else on the combobox, just like it does when dropdownstyle is DropDown or Simple.

In case you wondering why I want this, I have DrawMode set to OwnerDrawFixed and in the DrawItem I draw the combobox so it looks normal, not the ugly 3d that this dropdownstyle forces upon me. So I actually have a readonly combobox but without the ugly 3d look.

If requested I can post the code from the DrawItem, but this code does not has any influence on this behaviour because without the drawitem code the combobox reacts exactly the same.

I hope this question is clear enough.

1
this is something that you can actually fix yourself by reading MSDN ComboBoxDropDown DocumentationMethodMan
I just looked at that document but cannot find anything there that can help me. The example is for DropDownStyle = DropDown which is not what i am using. Maybe you could point me to the part in this document that I need ?GuidoG
Then what are you using as the default DropDownStyle..?MethodMan
dropdownstyle = DropDownList (its mentioned several times in the quesiton)GuidoG
can you show your actual code for one of the dropdownboxesMethodMan

1 Answers

1
votes

My good friend Google came to the resque, this piece of code seems to fix my problem:

const int WM_LBUTTONDOWN = 0x0201;
const int WM_LBUTTONDBLCLK = 0x0203;

protected override void WndProc(ref Message m)
    {
        // only open dropdownlist when the user clicks on the arrow on the right, not anywhere else...
        if (m.Msg == WM_LBUTTONDOWN || m.Msg == WM_LBUTTONDBLCLK)
        {
            int x = m.LParam.ToInt32() & 0xFFFF;
            if (x >= Width - SystemInformation.VerticalScrollBarWidth)
                base.WndProc(ref m);
            else
            {
                Focus();
                Invalidate();
            }
        }
        else
            base.WndProc(ref m);
    }