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

Problem with Multiselect when rowsourcetype = Field

Status
Not open for further replies.

MForrest

Programmer
Jun 9, 2003
85
GB
Hi all I have seen a few comments on this before but dont seem to have a solution. I can multiselect from my list fine but my problem is when I scroll the list the items in the list that were selected are deselected. I have two other lists on the same form but the rowsourcetype of those lists are a value and this problem does not occur. Is this just relating to a property that requires setting for a list with rowsourcetype - Fields from a cursor.

Any ideas

The following properties are set for my lists with both the rowsourcetype Value and Fields:
BoundTo = .F.
BoundColumn 0
ControlSource None
Rowsource = c_prefix_list
RowsourceType = Fields
 
Hi Kevin cheers for the reply, kind of in Limbo land with this one so many properties to get my head around.

Just changed the BoundColumn to 1 but it has not solved my problem Im afraid

 
Hi, I have just been working on that, here I am using the following code to store the values of the items that are selected in the list to a variable called List:

with thisform
FOR i=1 TO .listName.ListCount
IF .listName.Selected(i)
List = List + "," + .listName.LIST[i,1]
ENDIF
ENDFOR

Dont know why Im having problems when scrolling my list then. I happen to have a pageframe with different search criteria which can be selected on each of the pages of the pageframe, there are many lists amongst those pages two which have rowsource type Value and the other with a rowsourcetype Fields from a cursor. When I leave the page with the my cursor list to view another page and then go back to the page with the cursor list my items selected in the list remain but as soon as I scroll through the items in the list any selections dissappear.

If you dont mind could you let me know what settings you have for the following properties of the list or if you suspect if its related to another property setting for the listbox.

BoundTo
BoundColumn
ControlSource
Rowsource
RowsourceType

Hope I have helped, cheers
 
MForrest,

What version of VFP are you using?

-Kevin
 
MForrest,

Do you have any code firing on any of the control's events? The properties you have mentioned that you set are all okay. I suspect the problem is elsewhere. I would recommend trying to trap the problem by recreating the listbox, setting one property at a time, and checking to make sure it works before moving to the next. Or, if you have code firing in any of the events, double check it to make sure your mistake isn't there. Scrolling shouldn't affect your ability to multiselect. I duplicated your situation on a VFP6 machine and had no problems.


-Kevin
 
Thanks Kevin, just checked, was a good point as I know how tempremental some things can be but Its not fixed my problem, its so frustrating. Maybe its a setting on my pageframe as it only happens when I leave the page with my list and then go back to it, I can scrool the list fine if I stay within the page.
 
Yes, that is the problem. Sorry, I missed that earlier. You can set the lostfocus event of your listbox to store the values to an array and then set the gotfocus event of your listbox to re-select those values.

-Kevin
 
Hi Kevin I may have coded this wrong but I believe using the following code on the lostfocus and gotfocus event for the listbox does what it should but as soon as I hit the scroll bar to view the selections all selections are still cleared.

I was sure that idea would work, have I made an obvious mistake anywhere?

I have used the following on the lostfocus of the list:
Local list_count
list_count = 0
* clear array
for a = 1 to alen(a_prefix)
a_prefix[a] = ""
endfor
with thisform.pageframe1.page1
FOR i=1 TO .lstPrefix.ListCount
IF .lstPrefix.Selected(i)
list_count = list_count + 1
DIMENSION a_prefix[list_count]
a_prefix = .lstPrefix.value
ENDIF
ENDFOR
endwith

and the following on the gotfocus of the page this way the user can change selections on gotfocus of the listbox:
with thisform.pageframe1.page1
FOR i=1 TO .lstPrefix.ListCount
FOR j = 1 to alen(a_prefix)
IF alltrim(.lstPrefix.list(i)) == alltrim(a_prefix[j])
.lstPrefix.Selected = .t.
ENDIF
ENDFOR
ENDFOR
endwith
 
MForrest,

Sorry if it took a bit to reply. It's not emailing me to let me know you responded. Anyways, give me a few minutes to write and test the code. I'll post momentarily.

-Kevin
 
MForrest,

Well, I have good news and bad news. The bad news is, no matter what I try it still deselects. The good news is, that I came up with a working alternative that basically accomplishes the same end result. If you want the alternative, let me know.
-Kevin
 
Kevin thanks so much for investigating this for me, I have a good yet bad way of not being defeated which can drive me up the wall and waste a lot of time when i cant seem to fathom out a problem.

I will be very interested to see the alternative if its not to much trouble.
 
The alternative is basically pretty simple. Rather than having 1 listbox on the page, use 2. The second one shouldn't have a rowsource. What you can do is place code in the doubleclick event of the first listbox that takes the selected value and adds the item to the new list box. You can the add code to the doubleclick event of the new listbox that deletes the selected item. This way, as long as the form is open, the selected values will remain in the new listbox, regardless of if the user navigates to a differnet page in the pageframe. You can then use a for loop with .listcount to go thru the list and give you all the values.

Hope this helps.

Kevin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top