Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3931418
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:20:59+00:00 2026-05-19T23:20:59+00:00

I have a form which has a Combo Box Control. I have selected the

  • 0

I have a form which has a Combo Box Control. I have selected the drop down style property to DropDown. I have also set the DropDown Width to 250. I have set the auto complete mode to suggest and the auto complete source to listitems. it works absolutely fine when i click on the drop down. but when i type in somethin, the auto complete mode activates a drop down which has a small width.

any help appreciate. i wanna know how to increase the width of the auto complete drop down via code so that the list items are viewed properly. I am using C#.

I had asked this a couple of months back but didn’t get a proper answer. now the customer wants it bad 🙁
??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T23:21:00+00:00Added an answer on May 19, 2026 at 11:21 pm
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;
    using System.Runtime.InteropServices;
    using System.Text;
    using System.Windows.Forms;
    
    /// <summary>  
    /// Represents an ComboBox with additional properties for setting the   
    /// size of the AutoComplete Drop-Down window.  
    /// </summary>  
    public class ComboBoxEx : ComboBox
    {
    private int acDropDownHeight = 106;
    private int acDropDownWidth = 170;
    
    
    //<EditorBrowsable(EditorBrowsableState.Always), _  
    
    [Browsable(true), Description("The width, in pixels, of the auto complete drop down box"), DefaultValue(170)]
    public int AutoCompleteDropDownWidth
    {
        get { return acDropDownWidth; }
    
        set { acDropDownWidth = value; }
    }
    
    
    //<EditorBrowsable(EditorBrowsableState.Always), _  
    
    [Browsable(true), Description("The height, in pixels, of the auto complete drop down box"), DefaultValue(106)]
    public int AutoCompleteDropDownHeight
    {
        get { return acDropDownHeight; }
    
        set { acDropDownHeight = value; }
    }
    
    
    protected override void OnHandleCreated(EventArgs e)
    {
        base.OnHandleCreated(e);
    
        ACWindow.RegisterOwner(this);
    }
    
    #region Nested type: ACWindow
    
    /// <summary>  
    /// Provides an encapsulation of an Auto complete drop down window   
    /// handle and window proc.  
    /// </summary>  
    private class ACWindow : NativeWindow
    {
        private static readonly Dictionary<IntPtr, ACWindow> ACWindows;
    
        #region "Win API Declarations"
    
        private const UInt32 WM_WINDOWPOSCHANGED = 0x47;
    
        private const UInt32 WM_NCDESTROY = 0x82;
    
    
        private const UInt32 SWP_NOSIZE = 0x1;
    
        private const UInt32 SWP_NOMOVE = 0x2;
    
        private const UInt32 SWP_NOZORDER = 0x4;
    
        private const UInt32 SWP_NOREDRAW = 0x8;
    
        private const UInt32 SWP_NOACTIVATE = 0x10;
    
    
        private const UInt32 GA_ROOT = 2;
        private static readonly List<ComboBoxEx> owners;
    
    
        [DllImport("user32.dll")]
        private static extern bool EnumThreadWindows(int dwThreadId, EnumThreadDelegate lpfn, IntPtr lParam);
    
    
        [DllImport("user32.dll")]
        private static extern IntPtr GetAncestor(IntPtr hWnd, UInt32 gaFlags);
    
    
        [DllImport("kernel32.dll")]
        private static extern int GetCurrentThreadId();
    
    
        [DllImport("user32.dll")]
        private static extern void GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);
    
    
        [DllImport("user32.dll")]
        private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy,
                                                uint uFlags);
    
    
        [DllImport("user32.dll")]
        private static extern bool GetWindowRect(IntPtr hWnd, ref RECT lpRect);
    
        #region Nested type: EnumThreadDelegate
    
        private delegate bool EnumThreadDelegate(IntPtr hWnd, IntPtr lParam);
    
        #endregion
    
        #region Nested type: RECT
    
        [StructLayout(LayoutKind.Sequential)]
        private struct RECT
        {
            public readonly int Left;
    
            public readonly int Top;
    
            public readonly int Right;
    
            public readonly int Bottom;
    
    
            public Point Location
            {
                get { return new Point(Left, Top); }
            }
        }
    
        #endregion
    
        #endregion
    
        private ComboBoxEx owner;
    
        static ACWindow()
        {
            ACWindows = new Dictionary<IntPtr, ACWindow>();
    
            owners = new List<ComboBoxEx>();
        }
    
    
        /// <summary>  
        /// Creates a new ACWindow instance from a specific window handle.  
        /// </summary>  
        private ACWindow(IntPtr handle)
        {
            AssignHandle(handle);
        }
    
    
        /// <summary>  
        /// Registers a ComboBoxEx for adjusting the Complete Dropdown window size.  
        /// </summary>  
        public static void RegisterOwner(ComboBoxEx owner)
        {
            if ((owners.Contains(owner)))
            {
                return;
            }
    
            owners.Add(owner);
    
            EnumThreadWindows(GetCurrentThreadId(), EnumThreadWindowCallback, IntPtr.Zero);
        }
    
    
        /// <summary>  
        /// This callback will receive the handle for each window that is  
        /// associated with the current thread. Here we match the drop down window name   
        /// to the drop down window name and assign the top window to the collection  
        /// of auto complete windows.  
        /// </summary>  
        private static bool EnumThreadWindowCallback(IntPtr hWnd, IntPtr lParam)
        {
            if ((GetClassName(hWnd) == "Auto-Suggest Dropdown"))
            {
                IntPtr handle = GetAncestor(hWnd, GA_ROOT);
    
    
                if ((!ACWindows.ContainsKey(handle)))
                {
                    ACWindows.Add(handle, new ACWindow(handle));
                }
            }
    
            return true;
        }
    
    
        /// <summary>  
        /// Gets the class name for a specific window handle.  
        /// </summary>  
        private static string GetClassName(IntPtr hRef)
        {
            var lpClassName = new StringBuilder(256);
    
            GetClassName(hRef, lpClassName, 256);
    
            return lpClassName.ToString();
        }
    
    
        /// <summary>  
        /// Overrides the NativeWindow's WndProc to handle when the window  
        /// attributes changes.  
        /// </summary>  
        protected override void WndProc(ref Message m)
        {
            if ((m.Msg == WM_WINDOWPOSCHANGED))
            {
                // If the owner has not been set we need to find the ComboBoxEx that  
    
                // is associated with this dropdown window. We do it by checking if  
    
                // the upper-left location of the drop-down window is within the   
    
                // ComboxEx client rectangle.   
    
                if ((owner == null))
                {
                    Rectangle ownerRect = default(Rectangle);
    
                    var acRect = new RECT();
    
                    foreach (ComboBoxEx cbo in owners)
                    {
                        GetWindowRect(Handle, ref acRect);
    
                        ownerRect = cbo.RectangleToScreen(cbo.ClientRectangle);
    
                        if ((ownerRect.Contains(acRect.Location)))
                        {
                            owner = cbo;
    
                            break; // TODO: might not be correct. Was : Exit For
                        }
                    }
    
                    owners.Remove(owner);
                }
    
    
                if (((owner != null)))
                {
                    SetWindowPos(Handle, IntPtr.Zero, -5, 0, owner.AutoCompleteDropDownWidth,
                                 owner.AutoCompleteDropDownHeight, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
                }
            }
    
    
            if ((m.Msg == WM_NCDESTROY))
            {
                ACWindows.Remove(Handle);
            }
    
    
            base.WndProc(ref m);
        }
    }
    
    #endregion
    }
    

    This is what I did and it actually works really well. Good to find an answer atlast 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ASP.NET page which has a form on it. It also has
I have a form which has a lot of SELECTs. For various reasons, I'd
I have an ASP.NET page which has a script manager on it. <form id=form1
I have a form which is used to insert/display and update . In the
I have a form which takes both the user details and an image uploaded
In my Rails app, I have a form which redirects through a foreign service,
I have a form in which people will be entering dollar values. Possible inputs:
I have a form in which the user can choose a component type from
I have a C# form into which I've placed a left-docked MenuStrip . This
I have a an HTML form which contains the YAHOO rich text editor on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.