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

Programmatically Loading & Referencing Listbox Items

ListBox

Programmatically Loading & Referencing Listbox Items

by  jimoo  Posted    (Edited  )
1. Create a new form and add a listbox.
2. Set ColumnCount = 3
3. Set ColumnWidths to 110,110,110
4. Put the following code in FORM init Event:

FOR lni = 1 TO 3
DO CASE
CASE lni = 1
lcValue = "Mickey"
CASE lni = 2
lcValue = "Donald"
OTHERWISE
lcValue = "Goofey"
ENDCASE

THISFORM.list1.ADDLISTITEM(lcValue + " A ",lni,1)
THISFORM.list1.ADDLISTITEM(lcValue + " B ",lni,2)
THISFORM.list1.ADDLISTITEM(lcValue + " C ",lni,3)
ENDFOR

5. Add a button
6. Place the following code in the click event of the button:


FOR lni = 1 TO THISFORM.list1.LISTCOUNT
MESSAGEBOX(THISFORM.list1.LISTITEM(lni,1))
MESSAGEBOX(THISFORM.list1.LISTITEM(lni,2))
MESSAGEBOX(THISFORM.list1.LISTITEM(lni,3))
ENDFOR

THISFORM.RELEASE

7. Save and execute the form.

This demonstrates how you can programmatically load the items, and then reference them individually.

If you would like to see how to take the multi-column list items from this item, and move them to another multi-column list continue with step 8.

8. Add another listbox to the form. It probably has the name of list2.

9. In the double-click event of list1, add the following code:

lnList2Count = THISFORM.list2.ListCount + 1

THISFORM.List2.ADDLISTITEM(this.List(this.listindex,1),lnList2Count,1)
THISFORM.List2.ADDLISTITEM(this.List(this.listindex,2),lnList2Count,2)
THISFORM.List2.ADDLISTITEM(this.List(this.listindex,3),lnList2Count,3)

This.RemoveItem(This.ListIndex)

10. Size list boxes, save & run code.
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top