Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check box in Combobox

Status
Not open for further replies.

abbasaif

ISP
Oct 8, 2018
89
AE
Hi,

How can I put check box in a combo box??

Please guide

abbasaif
 
You can partially. Just like the Listbox the Combobox has the Picture property in two variations: As single property specifying a picture for all items and as Picture array.

You have to use the Combobox with its ListItem array instead of rowsourcetype cursor or fields because that doesn't mix with array index = recno() or something along these lines.
And once you have an unchecked box as image there's no automatic checking it. So you have to emulate this, and it won't suppress the usual color inversion of picked items.

I'd not go that route for mere look&feel reasons. The combobox collapses its list after a single pick anyway. A list of checked or unchecked items is best shown in a grid, where you can also put a real checkbox control into a column, that automatically acts as a checkbox and binds to a field.

Bye, Olaf.

Olaf Doschke Software Engineering
 
And if you want to know how to add a checkbox to a grid, see this article:

Yes, I am using different controls in grid.
I was wondering if I could do multiple selection.

Thanks for the reply!

grd_sc2awm.jpg


Abbasaif
 
You can do multiple selection in a listbox (not a combo box) simply by setting the MultiSelect property to .T. To make a multiple selection, users holds down Shift and/or Ctrl keys while clicking on an item. To find which items they have selected, you use the Selected property.

But it is awkward for the user, and susceptible to errors. If you are comfortable placing checkboxes in a grid, I suggest you stay with that.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
You can do multiple selection in a listbox (not a combo box) simply by setting the MultiSelect property to .T. To make a multiple selection, users holds down Shift and/or Ctrl keys while clicking on an item. To find which items they have selected, you use the Selected property.

Yes, I did that also. see

abbasaif

lstbox_xtmwlu.jpg
 
So what speaks for a checkbox in a combo? A combobox in itself doesn't allow multiselect, it is designed for a single value it stores in its Value property and stores back into the controlsource after picking an item. Even if you manage to display unchecked and checked boxes in the dropdown list portion of a combo and disregard its value, what is your gain? Needing less place? You can shrink a listbox or grid via height, you can use pageframes, also without tabs, you can scroll a form. Just to name three things saving space. But you just cause more trouble than it's worth to include checkboxes in a combobox. I don't see any other reason to have this. Maybe you find ActiveX controls supporting such a design, but it is extremely useless in my personal opinion, even for space saving layouts.

Bye, Olaf.

Olaf Doschke Software Engineering
 
Thanks for the reply!

Actually I want to put the combo box instead of text box on the top of the grid header as shown in image.
Where users can select multiple categories instead of checking each item through check box.
If user check any category, it should check all the item codes accordingly.

Thanks

grd1_bey41c.jpg


Abbasaif
 
Ah, that at least explains the motivation.

Well, see what Excel does? It puts a dropdown arrow button within the header caption. So indeed every header at first glance looks like a combobox. But it isn't really a combobox. The dropdown simply is something like a form or container. You could do the latter in VFP, too. So don't use a combobox, just add a button there and let that show a container "dropping down" (you don't have to animate it, rather set it visible =.t. or create it at that moment). Then use a multiselect listbox in that container and two buttons OK and Cancel.

It's up to you what you show when the user closes that container with OK or Cancel. Maybe just change a button caption from "pick categories" to "picked categories" to indicate the column is actively filtering data and back to "pick categories" when no category is picked and data isn't filtered by that column filter control. A normal combobox - even if it had multi-select - would still not be able to show all picks in the one row in the collapsed state.

As your layout already differs from Excels idea to have that within the header make the best of that, you're free to do whatever you want. In case of a textbox for entering a filter value, it is even simpler to use as Excels way, but in this case, I'd just use a button. Maybe a textbox plus a button, and then an extra container, or even a form you position there, set without titlebar. Whatever, but you are not the owner of the dropdown portion of a combobox, so use something else.

Bye, Olaf.

Olaf Doschke Software Engineering
 
Thanks Mr.Olaf, I got some idea from your valuable suggestion.

Let me try it!!

Abbasaif
 
Yes, Mr. Olaf

I created a button inside a container which contains a grid also. Same like shown above.
Initially the container size is same as button size and no sooner it is clicked, it opens to a certain size with give and check box.

Category is selected and clicked the same button (toggle) which close the container and checked the respective item codes boxes related to the same category.

At last my I go the solution.

Thanks for the time sharing with me.

Abbasaif
 
Good idea.

The only thing not nice about such containers you resize or switch in their visibility is design time handling of them. I guess you created the full-size container on the form and resized it to button size after you were finished. Now to change something in this you'd need to resize the container at design time to make the change and then resize it back. (Just an assumption)

Here really OOP and creating such a container as a class of a VCX can help. You can code and design as you like, keep the container at its expanded full size, you drag&drop the class on the form and shrink it as you like and you never need to go back and forth again. Any change you do in the full-size class, the object on the form still is shrunk down.

There are also some more strategies to let such a container control its own size in itself with init already, so you don't change that manually or as I also already hinted just creating such things at runtime at first use.

A new extra form has some hurdles too, and some things the container does not: Scrollbars. But before I tear down everything you just built, I conclude with the recommendation you stick to what you have and see how it works out, then come back for a second generation redesign later with the experience made.

Bye, Olaf.

Olaf Doschke Software Engineering
 
Yes, Mr. Olaf

I created this container as class and using it wherever is required in other forms.

Thanks a lot!

Abbasaif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top