LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Selecting multiple items in List Box using Shift key?

It appears that there is no native capability within a List Box control (with Check Mode enabled) to select a range of items while holding the <Shift> key while left-clicking.  Is there a way this can be accomplished programmatically?  The Tree control seems to allow this, but I was hoping I could use the simpler List Box control.
0 Kudos
Message 1 of 6
(5,474 Views)

In my opinion it's not possible to highlight more than one line at a time in a listbox, not even programmatically: this control by itself can have only one "active" row at a time.

If you can "downgrade" to a simple textbox, you could rely on highlighting facilities of this control, using ATTR_TEXT_SELECTION_START and ATTR_TEXT_SELECTION_LENGTH attributes combined with GetTextBoxLineIndexFromOffset ( ) function to obtain all the lines highlighted by the operator.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 6
(5,459 Views)
I am not trying to highlight lines in the List Box.  When I say that I want to select items, I mean that I want to put a check mark next to each item.  I want to know if there's a way by which I could "check" a range of items with the Shift key.  I think I may be able to accomplish this programatically using GetGlobalMouseState.
0 Kudos
Message 3 of 6
(5,439 Views)
As you mentioned, you can use a tree control to do this.  You can also configure the tree control to look like a list control, and you can even use the list API (InsertListItem, etc).
 
To make the tree look like a list control, simply set a few attributes. For example, you could configure the tree like this and then pretend you have a listbox with multiple selection capability...
 
SetCtrlAttribute(panel, ctrl, ATTR_SHOW_CONNECTION_LINES, 0);
SetCtrlAttribute(panel, ctrl, ATTR_SHOW_PLUS_MINUS, 0);
SetCtrlAttribute(panel, ctrl, ATTR_FULL_ROW_SELECT, 1);
SetCtrlAttribute(panel, ctrl, ATTR_ENABLE_DRAG_DROP, 0);
SetTreeItemAttribute(panel, ctrl, VAL_DFLT_FOR_NEW_OBJECTS, ATTR_NO_EDIT_LABEL, 1);
SetCtrlAttribute(panel, ctrl, ATTR_ENABLE_POPUP_MENU, 0);
 
To use check marks, you have to enable the show marks attribute...
 
SetCtrlAttribute(panel, ctrl, ATTR_SHOW_MARKS, 1);
 
Tree items by default have their ATTR_MARK_TYPE set to VAL_MARK_CHECK, which is probably what you want. Each item will have a check box next to it instead of the check column that the listbox has, but it behaves the same way. You could also enable ATTR_DRAGGABLE_MARKS if you want to be able to change check mark status by dragging with the mouse.
 
 
- jared
0 Kudos
Message 4 of 6
(5,438 Views)
Oh, I thought you meant that you wanted to highlight items in the list box. You could check a range of items programmatically in the callback based on whether the shift key is down (using GetGlobalMouseState). You would have to keep track of the previous active item in order to know the range to check using CheckListItem.
 
You could keep track of the active item with EVENT_VAL_CHANGED.
 
If all you want to do is allow the user to select a lot of items quickly, you could just enable ATTR_DRAGGABLE_MARKS, which would allow the user to select multiple items by dragging the mouse in the check column while the left button is down.
 
- jared
0 Kudos
Message 5 of 6
(5,432 Views)
I had been wondering what draggable marks were!  I think that accomplishes the same thing I wanted to do with the <Shift> key.  Thanks for the explanation.  I think I will stick with the List Box because the Tree control check marks seem to act independently from the row selection and I would have to do extra programming to get them to act as one.
0 Kudos
Message 6 of 6
(5,423 Views)