Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Trying to populate a listbox
Message
 
To
12/01/2006 18:12:21
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
01086295
Message ID:
01086519
Views:
15
>In my form I have this example for testing: but it never gets populated, can you tell me why?
>
>DIMENSION gaMyArray(5)
>FOR gnCount = 1 to 5
>   STORE gnCount TO gaMyArray(gnCount)
>NEXT
>thisForm.List1.RowSourceType = 5
>thisForm.List1.RowSource = "gaMyArray"
>thisform.list1.additem(gaMyArray(1,1))
>thisform.list1.additem(gaMyArray(1,2))
>thisform.list1.additem(gaMyArray(2,1))
>thisform.Refresh
>thisform.list1.Requery()
>?thisForm.List1.Value

>
>You are mixing up 2 different ways of populating a listbox. If you want to use an array to populate it, make the array an array property of your form, or even better, give your base class listbox an array property called aContents so you class wil be encapsulated better.
>
>If you want to use an array RowSource, you do it like so:
>
>
>DIMENSION Thisform.aContents[ 5 ]
>FOR lnI = 1 TO 5
>  Thisform.aContents[ lnI ] = lnI
>ENDFOR
>WITH Thisform.List1
>  .RowSourceType = 5
>  .RowSource = "Thisform.aContents"
>  .Requery()
>  .ListIndex = 1
>ENDWITH
>
>
>If you want to populate it yourself, you need to leave the RowSourceType at 0-None and use code like this in the List box's Init() to populate it:
>
>
>WITH This
>  .BoundColumn = 2
>  .BoundTo = .T.
>  .AddItem( [One] )
>  .List[ .NewIndex, 2 ] = [1]
>  .AddItem( [Two] )
>  .List[ .NewIndex, 2 ] = [2]
>  .AddItem( [Three] )
>  .List[ .NewIndex, 2 ] = [3]
>  .AddItem( [Four] )
>  .List[ .NewIndex, 2 ] = [4]
>  .AddItem( [Five] )
>  .List[ .NewIndex, 2 ] = [5]
>  .LIstIndex = 1
>ENDWITH
>
>
>You might want to take a look at the first dozen or so pages in chapter 5 of 1001 Things You Wanted to Know About Visual FoxPro. It gives you a brief overview of how combos and lists work

Actually, I added a property to the form aContents[ 5 ], and it worked. I don't know what the diff is by making it a property????
"Build a man a fire, and he's warm for a day.
Set a man on fire, and he's warm for the rest of his life."
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform