Preventing the dropdown from being opened when drop down button pressed in combobox?
-
Hello All, I have an issues, i want to cancel the dropdown from being opened after validating the dropdown button clicked. i tried with setting droppeddown property to true as suggested by one of the member from this forum in earlier post. But that is also not avoiding the dropdown from being opened. I also tried to override the wndProc method and canceling the event it self but that is also not working . Please suggest me what i need to do so that i can avoid the dropdown after custom validation. Thanks in Advance. Ron
-
Hello All, I have an issues, i want to cancel the dropdown from being opened after validating the dropdown button clicked. i tried with setting droppeddown property to true as suggested by one of the member from this forum in earlier post. But that is also not avoiding the dropdown from being opened. I also tried to override the wndProc method and canceling the event it self but that is also not working . Please suggest me what i need to do so that i can avoid the dropdown after custom validation. Thanks in Advance. Ron
Hello, I think this can be done by intercepting WM_COMMAND message in "WndProc" method. this may help
public class SuperComboBox:ComboBox
{
public class DropDownValidate:EventArgs
{
public bool AllowDropDown{get;set;}public DropDownValidate() { this.AllowDropDown = true; } } private const int WM\_COMMAND = 0x0111; public event EventHandler<DropDownValidate> ValidateOnDropDown; private bool \_haltDrop; protected virtual void OnValidateDropDown(DropDownValidate e) { if (this.ValidateOnDropDown != null) this.ValidateOnDropDown(this, e); } protected override void WndProc(ref Message m) { if (m.Msg == WM\_COMMAND) { var validationArg = new DropDownValidate(); this.OnValidateDropDown(validationArg); \_haltDrop = !validationArg.AllowDropDown; if (\_haltDrop) return; } base.WndProc(ref m); } }
Good luck