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 put a combo box into a Popup and prevent the dropdown from closing when clicked on it?

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

 

Normally, when you put a combo box into a popup, the popup will be hidden when you click on the combo box drop-down. This is because the popup framework expects the windows you activate to be .NET control based, otherwise it just gives up.

To work around this problem, use a custom PopupControlContainer, as follows. Check out the inline comments.

C#

public class CustomPopupControlContainer : PopupControlContainer

{

  public CustomPopupControlContainer()

  {

  }

  public CustomPopupControlContainer(IContainer container):this()

  {

   container.Add(this);

  }

  public override bool IsRelatedControl ( System.Windows.Forms.Control control , System.Boolean askPopupParent )

  {

   bool isrelated = base.IsRelatedControl(control, askPopupParent);

   // This will be the case when native windows without dotnet wrappers are encountered

   // like the combo box dropdown.

   if(control == null && !isrelated)

   {

    // If so, then go ahead and get a dotnet parent control.

    IntPtr hwnd = GetFocus();

    // This method goes up the hierarchy looking for a dotnet parent.

    Control dotnetParent = PopupUtils.GetADotNetParentControl(hwnd);

    if(dotnetParent != null)

    // if found then check if that is a related control, instead.

    isrelated |= base.IsRelatedControl(dotnetParent, askPopupParent);

   }

   return isrelated;

  }

[DllImport("user32.dll", CharSet=CharSet.Auto, CallingConvention=CallingConvention.Winapi)]

public static extern IntPtr GetFocus();

[DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true, CallingConvention=CallingConvention.Winapi)]

public static extern IntPtr GetParent(IntPtr hwnd);}

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.

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