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

Populate one list box with items from another - endless loop 1

Status
Not open for further replies.

jworley

Programmer
Jun 19, 2000
36
GB
Hi, I used the moverlists example for a form where I want to let a user select/deselect invoice lines for printing/posting. When I set the first list to look at the invoice line table, using the button that transfers all of the records from the first list to the second results in foxpro freezing (I assume that it's looping continously).

I've also tried this using an array and a cursor as the data source, it does the same (works fine just transferring one item at a time, though). Any ideas ?

Code I'm using on the "transfer all" button:

do while thisform.listFrom.ListCount > 0
thisform.listTo.AddItem(thisform.listFrom.List(1))
thisform.listFrom.RemoveItem(1)
enddo
thisform.listFrom.refresh


Jim Worley
jim@aits-uk.net
15 years practical IT experience from sales to support to development plus B.Sc. (Hons) Computer Studies, fluent German speaker, willing to have a go at anything and don't suffer fools gladly !
 
Hi
Try..
Code:
FOR lnCounter= 1 TO thisform.listFrom.ListCount 
   thisform.listTo.AddItem(thisform.listFrom.List(lnCounter))
ENDFOR
Your assumption about the logic behind the list box functionallty is not right. Trace in your program and check the value of thisform.listFrom.ListCount after you remove an item this will give you an idea about what is going on.
I believe this condition
Code:
do while thisform.listFrom.ListCount > 0
is always true.
Thanks Walid Magd
Engwam@Hotmail.com
 
Hi Walid,

The condition "do while xxx.ListCount > 0" is NOT always true, it becomes true due to xxx.RemoveItem(1) decrementing xxx.ListCount all the way to zero. I, like you, thought this might be the problem, but the code works fine when straight values such as a,b,c,d are used for the list box rowsource as opposed to fields from a table which is where the problem occurs. I think the problem has got to be something data source linked, i.e something to do with datasources of more than one dimension. Any ideas anyone ?



Jim Worley
jim@aits-uk.net
15 years practical IT experience from sales to support to development plus B.Sc. (Hons) Computer Studies, fluent German speaker, willing to have a go at anything and don't suffer fools gladly !
 
Hi Jim,

but the code works fine when straight values such as a,b,c,d are used for the list box rowsource as opposed to fields from a table

That's your answer. In order for the RemoveItem method to work as you are trying to use it, you'll have to set the RowSourceType property to either 0-None or 1-Value and programmatically populate it with AddItem or AddListItem or a comma delimited list.

In order for you to use another RowSourceType, you'll have to delete the item from the data source and requery the listbox. Extremely slow in a tight loop, as yours above.

I'd be willing to bet the example you refer to, programmatically populates the listfrom listbox via the AddItem or AddListItem methods.

Additionally, if you are doing a "transfer all", remove all the items at once, not individually. For Instance, ISO:

Code:
do while thisform.listFrom.ListCount > 0
   thisform.listTo.AddItem(thisform.listFrom.List(1))
   thisform.listFrom.RemoveItem(1)
enddo

use this instead:

lnTotal = thisform.listFrom.ListCount
FOR lnCounter= 1 TO lnTotal
thisform.listTo.AddItem(thisform.listFrom.List(lnCounter))
ENDFOR
thisform.listFrom.Clear

It should help speed up the process slightly. Jon Hawkins
jonscott8@yahoo.com

The World Is Headed For Mutiny,
When All We Want Is Unity. - Creed
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top