Click here to Skip to main content
15,390,470 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
I am searching a lot to find how to put a button inside listbox. The purpose is to close the listbox. If not , on document click I want to close listbox.
Can any one guide me.
Posted
Comments
Zafar Sultan 26-Dec-12 10:12am
   
What do you mean by "closing" the listbox. How do you want to close it when it is not opened? Are you sure you are talking about listbox as it is a dropdownlist with multiple-selection option?
ZurdoDev 26-Dec-12 10:15am
   
You can use the onclick event of the body element but your description does not make a lot of sense. Maybe an illustration or example would help.
Yaseer Arafat 26-Dec-12 10:26am
   
Could you please give a brief description and some code block you used.
[no name] 26-Dec-12 11:34am
   
http://msdn.microsoft.com/en-us/library/system.windows.controls.itemscontrol.addchild.aspx
Sergey Alexandrovich Kryukov 26-Dec-12 12:46pm
   
Bad idea, I would say. Why? I noticed the beginners heavily suffer from "button sickness", as if they were not the users themselves.
—SA
_Amy 26-Dec-12 23:24pm
   
What have you tried so far? Any dummy codes?

Makes no sense at all. Please also see my comment. The whole notion of "close" is something undetermined. What is supposed to happen, exactly?

Probably, the list box can disappear, and its place will be taken by some other controls. But even if you have such design, don't put a button. No normal user expects a "Close" button, especially insider the control itself. If you look around, you will see that there is no such metaphor at all. Even a window (form) is not closed by something in its area. Look thoroughly: it is closed by a button which is in the window non-client area.

So, you can do something similar, the way the behavior is expected. Put your list box (or a number of control) on a visually separated panel (borders, color), and have a small crossed-box button in the right top corner of this panel. Only in this case the user will immediately see what to do.

Better yet, review the design based on removing of UI elements, design something more usual. One typical suggestion would be the TabControl. I cannot give any specific advice without knowing your detail.

—SA
   
v2
Comments
Mike Hankey 26-Dec-12 13:31pm
   
Sergey,
I wasn't somehow saying that by using the ListView as opposed to the ListBox that it was a reasonable or acceptable thing to do only that if he wanted to add the button for some reason not understood from his question that that would be the way to do it. Thanks for the vote!
Sergey Alexandrovich Kryukov 26-Dec-12 14:10pm
   
I don't question if you understand things correctly. I just wanted to clarify things. From your post one could understand that using a "Close" button in a list view is possible, which is of course true, and then assume it would be acceptable, which I would not agree, so I emphasize that this would be a bad design thing, no matter if its implementation is feasible or not. Hope I explained it.

Thank you, Mike.

—SA
Mike Hankey 26-Dec-12 14:43pm
   
I understand you and agree it's a bad design thing.
Sergey Alexandrovich Kryukov 26-Dec-12 16:38pm
   
Sure. Thank you, Mike.
—SA
S.Rajendran from Coimbatore 26-Dec-12 22:49pm
   
Your idea of a panel with a cross-box button is fine. Thank you, Sergey.
Rajendran
Sergey Alexandrovich Kryukov 26-Dec-12 23:40pm
   
You are welcome.
Then please accept the answer formally (green button) — thanks.
—SA
You cannot close a ListBox as it is a control on the form. Although if you want to put a button on a ListBox I would use a ListView as it can contain custom columns types as described here[^].
   
Comments
Sergey Alexandrovich Kryukov 26-Dec-12 12:57pm
   
More exactly, not just "you cannot", but it makes no sense; and the advice to use ListView would not be a good idea either, by the reasons I explained in my answer — please see.
Therefore, I voted 4, OK?
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900