Simulating Windows Explorer Style ComboBox problems - with .net ComboBox

  • Thread starter Deepak Malkan [Bentley]
  • Start date

D

Deepak Malkan [Bentley]

I am using to the Winforms ComboBox to simulate functionality similar to
that in the address-bar of Windows Explorer. Specifically, I want the
following functionality:

1. Indented items with image icons in drop down - I can simulate this by
setting DrawMode to OwnerDrawFixed.
2. Show the path of the selected item in the combobox text box - I trap the
selection the event on the ComboBox & set the required path as Text on the
ComboBox. But at some point out of my control, the ComboBox overwrites the
Text with the text associated with the selected item. How can I avoid this ?
3. Show the image associated with the text in the combobox text box - I can
do this only if the combobox drop-down style is set to DropDownList. I would
like to show the image when the combobox drop-down style is set to
"DropDown" - since I want the user to have the ability to modify the text in
the text box - similar to the ability Windows Explorer gives in its
addressbar.

In short, I want to simulate the exact same functionality & look&feel of the
Windows Explorer Addressbar using a .net ComboBox. Any help in resolving
problems raised in point 2 & 3 above will be helpful.

With Regards,

Deepak Malkan
Bentley Systems.
 
Ad

Advertisements

M

Mick Doherty

http://dotnetrix.co.uk/combobox.html --> Create an ImageCombo

That example should get you started.

To show the image in the ComboTextBox you will need to use interop to get
hold of and modify the textbox. The first example on this page shows how to
get a handle to the textbox.

You'll still need to do some work to get all the behaviour you want, but it
shouldn't be too difficult.
 
J

Jeffrey Tan[MSFT]

Hi Deepak,

Thanks for your post!!

For your request, we can first p/invoke FindWindowEx win32 API to find the
TextBox in combobox, then we have got the handle of that textbox, we can do
a subclassing to the TextBox with NativeWindow class in .Net. With the
NativeWindow subclassing, we got the Window Procedure of the textbox, at
last, we can intercept the drawing messages, and do the image drawing to
it. This technology is introduced in the article below:
"Adding an Icon or Control to a TextBox or ComboBox"
http://www.vbaccelerator.com/home/NET/Code/Controls/ListBox_and_ComboBox/Tex
tBox_Icon/article.asp

To display the customized text in the textbox, I think you can also
leverage the custom painting in the NativeWindow. Then combobox will not
overwrite your customized displayed path text.
==============================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Ad

Advertisements

Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top