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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to re-select multiselected listbox items

Status
Not open for further replies.

DanWalter

Programmer
Nov 29, 2000
58
US
Hello all. I have a legacy app that is resetting the selected listbox row to 1 by default. This is a multiselect list box. Under certain conditions, I am trying to re-establish the multiselect state the list was in. Here's how I'm trying:
* first the selected elements are copied to an array.
list1.multiselect = .T.
FOR i = 1 TO list1.listcount
IF ASCAN(laArray, list1.list(i)) > 0
list1.selected(i) = .T.
ENDIF
ENDFOR

What I end up with is the last item from the array being selected, and I lose all the other selections. In debug mode, I can see the selections traversing the list in order.

Any/all ideas much appreciated!
TIA,
Dan Dan Walter
DWalter@zoo.uvm.edu
 
Hi Dan,

As posted your code is straightforward and should work. Check to see that Multiselect stays set to .T.

Jim
 
Try it this way:

list1.multiselect = 1 &&... instead of .T.
Code:
STORE 0 TO nFirstItem
STORE .F. TO lFoundFirst
FOR i = 1 TO list1.listcount
    IF aArray[i] > 0 
        list1.selected(i) = .T.
        IF NOT lFoundFirst
           nFirstItem = i
           lFoundFirst = .T.
        ENDIF
    ENDIF
ENDFOR

list1.ListIndex = nFirstItem   
*...  ListIndex positions marker bar on first selected item
*...    without deselecting the rest.

Dave S.
 
Thanks all. The problem was the complexity of the app - a formset with activate code for nearly every object! The issue seemed to be that the listindex acted like it was going out of scope. I found three activate methods that changed the listindex and/or selected() properties, and once I manipulated both properties in all three places, the list behaved perfectly.

Thanks again!

Dan Dan Walter
DWalter@zoo.uvm.edu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top