Windows Develop Bookmark and Share   
 index > Windows Forms General > Help getting a control to display a pop-up list like the ComboBox's dropdown list?
 

Help getting a control to display a pop-up list like the ComboBox's dropdown list?

Hi peeps,

Im looking someone to help me understand how the ComboBox gets windows to draw the list. From what I can understand so far, it does some work into making the list a window and then uses that to send to the ShowWindow User32 API call to show the list, then uses the SetWindowPos to possition the list.

Any help in how it actualy does this process is what im looking for :)
  • Moved byTaylorMichaelLMVPFriday, September 25, 2009 1:54 PMWinForms related (From:Visual C# General)
  •  
Cadey  Friday, September 25, 2009 10:28 AM
An important step is to make the popupwindow a child of the desktop so it's not constrained by your application window boundaries.
Mattias, C# MVP
Mattias Sjögren  Friday, September 25, 2009 1:44 PM
I have thurther found out that the list is in fact a window and not just a control that is displayed. If this is correct then the problem is easy to resolved, however I was under the impression the dropdown was just a list, nothing more.
Cadey  Friday, September 25, 2009 1:48 PM
The drop down list is a class derived from NativeWindow that is defined by a nested class within the ComboBox class.

Use Red Gate's Reflector to browse the ComboBox class.

Mark the best replies as answers. "Fooling computers since 1971."
Rudedog2  Friday, September 25, 2009 5:00 PM
Hi Cadey,

The dropdown list of the ComboBox is a popup window like Mattias said, otherwise it won’t be able to extend itself beyond the parent window’s boundary. It has been wrapped by the ComboBox control so you don’t have to worry about the housekeeping details to make the dropdown work.

If you want to make a similar dropdown control which can be associated with a specified control, you can start from a Winform pop window. Make that form looks like dropdown control and put it right below (or above, depends on the space available) your control.

Could you please tell us more about what you want to achieve? That can help us to know the requirement clearly and find a solution.

Sincerely,
Kira Qian
Send us any feedback you have about the help from MSFT at fbmsdn@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework!
Kira Qian  Monday, September 28, 2009 7:34 AM
Hi Kira,

I have got the control working as you just suggested (by making the control that's visible a sub class of a Form) However I cant help this is a bit like using a sledge hammer to crack a nut.

Ive looked at a couple of working controls (like the CombBox and Status bar Drop Down menu) and they use the NativeWindow as there base on the menus. This is a little confusing however as I clearly see both of them using the List control to display the items, its confusing because a NativeWindow is not a control and so cannot hold any controls.

As for what I'm trying to achieve, I guess I'm just trying to do it "right" and not use things like a Form to get it work. Unless however that is the correct way to achieve making a control with a "top level" menu. Hope that makes sense?

Cadey  Monday, September 28, 2009 7:43 AM
Hi Cadey,

The ComboBox dropdown list is created use native method. It is not clear to us the detail information of the control design. If you use Reflector to view the source code of ComboBox, you can see a ComboBoxChildNativeWindow class inherited from NativeWindow . In the class, it calls COM interface (IAccessible Interface). This class will be used in the OnHandleCreated method.

If we want to implement this effect in Winform, the way you have taken is a proper solution. To call a lot of unmanaged method and escalade code permission very often is not a considered way.

Sincerely,
Kira Qian
Send us any feedback you have about the help from MSFT at fbmsdn@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework!
Kira Qian  Tuesday, September 29, 2009 7:08 AM
Yes, the dropdown of a ComboBox is a list box. It is unusual, it is a top-level window, not a child window. One reason it can extend beyond the bounds of the form. The .NET ComboBox class doesn't wrap it at all, it solely goes by the notification messages that the list box sends to the textbox portion of the ComboBox.

The only Control derived class in Windows Forms that can be a top-level control is the Form class. That's mostly due to the designer, top-level controls are very hard to manage in a designer. You can create your own non-Form top-level control but you'll have to do without all the WinForms goodies. You'll find the code you'll need in my answer on this web page.

Hans Passant.
nobugz  Wednesday, September 30, 2009 2:51 AM

You can use google to search for other answers

Custom Search

More Threads

• Internet explorer title bar
• how to select all records in datagrid view using check box column
• Combobox stability problem???
• Multilanguage WinForm application as a single EXE file
• MaskedTextBox and Currency
• Drawing Electrocardiogram (ECG) Efficiency
• Treeview Nodes.Add Problem
• grid view combo box and textbox ' event problem?
• Open a Dialog Box
• creating an install-like wizard