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

ListBox on the Fly #2 1

Status
Not open for further replies.

anyhandle

Programmer
Dec 1, 2000
57
US
Hi,

I just discovered that the value of a listbox created programmatically on the fly can be captured when cicking on another object. This isn't feasible after all. I need a way to determine if an object (listbox) exsists in order for this capturing code not to give an error. The other problem would be that I would have to put capture code in all objects for that listbox. Is there a way to create a listbox on the fly on the push of a button and to capture the value the user selects all within the same button?

Thanks

thisform.AddObject("List1","ListBox")
thisform.refresh
thisform.list1.Height=58
thisform.list1.Width=300
thisform.refresh
FOR lni = 1 TO 3
DO CASE
CASE lni = 1
lcValue = "Original Print Format"
CASE lni = 2
lcValue = "PDF"
OTHERWISE
lcValue = "PDF and Original Print Format"
ENDCASE

THISFORM.list1.ADDLISTITEM(lcValue,lni,1)
THISFORM.list1.ADDLISTITEM(lcValue,lni,2)
THISFORM.list1.ADDLISTITEM(lcValue,lni,3)
ENDFOR
thisform.list1.top=290
thisform.list1.left=288
thisform.list1.visible=.t.
thisform.list1.enabled=.t.
thisform.Refresh


 
You could do something like this:

IF PEMSTATUS(thisform,'list1',5) then

lcValue = thisform.list1.Value
ThisForm.RemoveObject("list1")
This.Caption = "List"

ELSE

DECLARE laListItem[3]

laListItem[1] = "Original Print Format"
laListItem[2] = "PDF"
laListItem[3] = "PDF and Original Print Format"

Thisform.AddObject("List1","ListBox")
WITH thisform.list1
.Height=58
.Width=300
.top=290
.left=288
.visible=.t.
.enabled=.t.
FOR x = 1 TO 3
.ADDLISTITEM(laListItem[x])
ENDFOR
ENDWITH
This.Caption = "Save"
ENDIF

This code checks to see if the object exists, if it does it save the selected list item to a variable (lcValue). If the object doesn't exist then it will create it. Paste this code into the click event of your button and see it it's what you wanted.

hope this helps

-Kevin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top