In MFC how to select multiple items in the Combo-box? - mfc

In MFC dialog based application, I have a combo box. Is it possible to select multiple items in the Combo-box through mouse and keyboard operations and also by pro-grammatically?
m_ctrlComboBox.AddString("Type1");
m_ctrlComboBox.AddString("Type2");
m_ctrlComboBox.AddString("Type3");
How to achieve it?

From the documentation:
A combo box consists of a list and a selection field. The list presents the options that a user can select, and the selection field displays the current selection. If the selection field is an edit control, the user can enter information not available in the list; otherwise, the user can only select items in the list.
The selection field is only capable of displaying a single selected item (at most). There is no way to allow a user (or code) to select multiple items at the same time. This is immediately obvious when looking at the CB_GETCURSEL and CB_SETCURSEL messages, that only allow for a single index to be passed.
A list view control allows multiple items to be selected at the same time.

Related

Prevent editable QComboBox selection from changing when item list modified

I have an editable QComboBox containing a list of ID numbers.
The ID numbers represent devices attached to the system. The devices are frequently added and removed at runtime.
The intent of the editable combo box is to contain, in its list, the list of IDs currently attached, for easy selection, but at the same time allow the user to manually enter IDs of devices not currently present. Also, it's valid to enter an empty string for the ID.
Basically I want to provide the user with a way to enter an arbitrary (or no) ID, with the added bonus of a quick selection of devices currently attached (which changes at runtime).
I am not currently using a list model to maintain the list, I'm just using the QComboBox's add and remove functions.
I need the selection to not change if devices are added or removed. However, I'm running into the following problems:
When the currently entered ID (either manually or by list selection) is removed from the list, the selection is changed to another ID in the list.
When the list is empty and an ID is entered manually, or no ID is entered at all, the selection is changed when an ID is added to the list.
Is there a way to make it so that adding and removing items from the combo box never, ever modifies the selection in the edit box? Or even some other UI element that accomplishes my goal?
Before updating the combo box, save the currently selected ID (or the blank string) to a temp. variable. After modifying the combo box contents, check if that ID still exists in the combo box (e.g. with findText()). If it does, select it with setCurrentIndex(). If it does not, set it with setCurrentText() or setEditText().

ListView32 - re-adding column doesn't restore data

I'm implementing show/hide column behaviour in a standard C++ Win32 application (no frameworks).
Say we've got 3 columns in a ListView control in Details view. The user has the option to show/hide the last two columns in order to see the extra detail if wanted or hide them to reduce clutter. All works well except that after the columns are deleted and then re-added, the data from the sub-items in those columns doesn't show up again, i.e. the columns are empty.
None of the items themselves have been altered in the meantime - do I lose the sub-item text when I delete the columns or I am missing something to force the columns to redraw the data?
Steps to reproduce:
1) Create a ListView32 control with 3 columns and add a bunch of items (and text to each of the items' sub-items). All good.
2) The user clicks "Hide Details", so I use LVM_DELETECOLUMN twice to remove the last two columns and they disappear. All good.
3) The user clicks "Show Details", so I use LVM_INSERTCOLUMN to add the last two columns and the headings appear, but the columns themselves are empty.
As an alternative, setting the column widths to zero is a hack and the user can still grab the re-size column splitter, so it's not a great option.
Many thanks for any suggestions.
Typically one does not store data in GUI. In case of plain listview32 you should add items specifying LPSTR_TEXTCALLBACK instead of real text and then handle LVN_GETDISPINFOW notification supplying (sub)item data. Windows will send this notification for all items. You can force Windows to retrieve data again by sending LVM_UPDATE message.
Setting the column widths is a viable solution. That is the way I do it in my UIs when columns can be shown and hidden dynamically. It works fine.
To prevent the user from resizing "hidden" columns, simply subclass the ListView using SetWindowLongPtr(GWL_WNDPROC) or SetWindowSubclass() to intercept HDN_BEGINTRACK notifications from the ListView's header control:
Notifies a header control's parent window that the user has begun dragging a divider in the control (that is, the user has pressed the left mouse button while the mouse cursor is on a divider in the header control). This notification code is sent in the form of a WM_NOTIFY message.
...
Returns FALSE to allow tracking of the divider, or TRUE to prevent tracking.

Tkinter - Changing the list in Option Menu

Is there a way to manipulate the List displayed by the OptionMenu in respect to what the user has currently selected?
For example, let's say I have a list - ["A","B","C"].
If the user currently selected A then if he clicks the optionmenu with A currently selected, what he will see in the list is not the original list but only B and C.
If he switches his answer from, let's say, A to B, then now, he will only see A and C in the OptionMenu.
And the same will follow if he chose B or C.
Thanks!
The OptionMenu widget is a button that shows a dropdown menu when pressed. You might do better to use a ttk.Combobox instead as that is a more modern UI element and you can very simply configure the values configuration item.
You can configure the attached menu at runtime. You access the menu using optionmenu['menu'] and you can then query items on the menu optionmenu['menu'].entrycget(0, 'label') or use entryconfigure to modify the items. Or you can delete items optionmenu['menu'].delete(index) and add new items. See the menu documentation for hints on manipulating the menu entries.

Dealing with huge select lists

I often use select lists with my projects but when it comes to a huge select list, I couldn't find a solution. I need a easy, plug and play solution for solution will be used in a few places.
When you have a select box or text box to be filled from a model data, I want to show user a text box, right side of text box, there should be a button to choice the value. Upon clicking that button, popup or a modal will be opened and I filter all the records and find my value, upon clicking value, modal or popup closes and I get choosen value to form control.
İmagine you have a text box to choose your customer, and among 2500 customer,
PS:don't suggest autocomplete, don't want to accomplish it.
Why don't you look at something like Chozen plugin http://harvesthq.github.io/chosen/. It allows you to easily search large select lists

AutoSuggestion in Combobox

I created a Combobox with CreateWindowEx. Everything goes well. But I would like to make a final feature: AutoSuggestion. The Combobox is used to do search text in a document, hence at some point, it have items that are the strings a user searched. The AutoSuggestion should be: drop down the list of items, find those items that begin with the string that a user typed in the edit control, but do not select one of them, do not display all other items, and finally do not change select item when keydown or keyup occurs, only highlight the item and select only when a user press Enter. Do you have any idea how to accomplish this task?
It sounds like you want Autocomplete functionality.