We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to prevent the form containing the combo from getting deactivated when pressing mouse-down on the drop-down list box

Platform: WinForms |
Control: ComboBoxBase |
Published Date: April 30, 2011 |
Last Revised Date: July 10, 2014

 

This is assuming you are using a list box as your drop-down ListControl:

The reason the combo-containing form gets deactivated is because when you mouse-down on the list box, it activates its parent form (the list box itself will be hosted on a borderless form).

You can work around this by deriving from a list box as follows and using it in place of the list box:

C#

public class StaticListBox : ListBox

{

   protected override void WndProc(ref Message m)

   {

     // Prevent the list box from processing the LeftMouse Down message,

     // since it activates it's parent Form in it's Default Wnd Proc.

     if(m.Msg == 0x201/*WM_LBUTTONDOWN*/)

     {

       return;

     }

   base.WndProc(ref m);

   }

}

 

VB

Public Class StaticListBox Inherits ListBox

   Protected Overrides Sub WndProc(ByRef m As Message)

     ' Prevent the list box from processing the LeftMouse Down message,

     ' since it activates it's parent Form in it's Default Wnd Proc.

     If m.Msg = 0x201 Then

       Return

     End If

     MyBase.WndProc( m)

   End Sub

End Class

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon