How to hide DropDownList in ComboBox?
I want use ComboBox only for displaying text.
This control look nice, for me is better than TextBox plus Button.
So control must be enabled, but without any items.
When user click arrow (or alt + down key) DropDownList should'n show, because ill select value from custom DataGridView in order to fill back text in ComboBox.
Edit. Alternative solution is set DropDownHeight to 1, with show only 1 pixel line after clicking control.
Edit. Real solution. Answer below
You can intercept the messages that cause the box to drop-down, in a subclass. The following snippet defines a control NoDropDownBox, that ignores the mouse clicks that result in a drop-down of the combo box:
public class NoDropDownBox : ComboBox
{
public override bool PreProcessMessage(ref Message msg)
{
int WM_SYSKEYDOWN = 0x104;
bool handled = false;
if (msg.Msg == WM_SYSKEYDOWN)
{
Keys keyCode = (Keys)msg.WParam & Keys.KeyCode;
switch (keyCode)
{
case Keys.Down:
handled = true;
break;
}
}
if(false==handled)
handled = base.PreProcessMessage(ref msg);
return handled;
}
protected override void WndProc(ref Message m)
{
switch(m.Msg)
{
case 0x201:
case 0x203:
break;
default:
base.WndProc(ref m);
break;
}
}
}
You will have less trouble and create a better end result by simply creating a usercontrol with a textbox and button that is styled in the way you want. If you figure out a way to remove the functionality of the combobox, all you're really doing is creating unneeded complexity.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With