Multi/Single selection in a ListBox
-
I have a dialog with a listbox. For some invocations of the dialog, I want the listbox to be multi-selection and for other invocations, the listbox should be single-select. In OnInitDialog(), I used ModifyStyle() to change the selection style. But this did not work. Is there a solution without subclassing CListBox?
-
I have a dialog with a listbox. For some invocations of the dialog, I want the listbox to be multi-selection and for other invocations, the listbox should be single-select. In OnInitDialog(), I used ModifyStyle() to change the selection style. But this did not work. Is there a solution without subclassing CListBox?
There are 2 possible ways - 1) Derive your class from CListBox with multiselect style and handle selection event (mouse and keyboard) depends on the mode you have - allowing or dissallowing to select more then 1 item. 2) Every time you changing multiselect style - recreate control.
-
There are 2 possible ways - 1) Derive your class from CListBox with multiselect style and handle selection event (mouse and keyboard) depends on the mode you have - allowing or dissallowing to select more then 1 item. 2) Every time you changing multiselect style - recreate control.
I did not make myself sufficiently clear. I have a list box in a dialog. Depending on an argument to the constructor of the dialog, I want to make this list box either single selection or multi-selection. However, once the selection style is set, It will not change for till the dialog is dismissed. In the resource editor, I'll set selection type to be 'single selection'. Depending on the argument to the constructor, I want to modify the selection type to 'Multi-Selection'. Is there a simple way of doing this without recreating the ctrl or deriving a class from CListBox. I tried ModifyStyle(0, LBS_MULTIPLESEL) in the OnInitDialog() of the dialog. This did not work. Hence this post.
-
I did not make myself sufficiently clear. I have a list box in a dialog. Depending on an argument to the constructor of the dialog, I want to make this list box either single selection or multi-selection. However, once the selection style is set, It will not change for till the dialog is dismissed. In the resource editor, I'll set selection type to be 'single selection'. Depending on the argument to the constructor, I want to modify the selection type to 'Multi-Selection'. Is there a simple way of doing this without recreating the ctrl or deriving a class from CListBox. I tried ModifyStyle(0, LBS_MULTIPLESEL) in the OnInitDialog() of the dialog. This did not work. Hence this post.
"Depending on an argument to the constructor of the dialog..." Well, if you have dialog on the resource it will have the styles specified in resource editor, how can you change it? It doesnot create dialog like window. It loads it from the resource. Well, another option - create 2 dialogs in resource editor with different styles and load appropriate dialog from the resource.