Yeung,
The problem is that the array only exists while the Init() method is executing. When the Init() finishes the array disappears and takes away the data for the listbox to display.
There are 3 easy solutions to this
1) use a form level array, that will maintain scope throughout the lifetime of the listbox:
DIMENSION thisform.adata(3)
with thisform
.adata[1]="a"
.adata[2]="b"
.adata[3]="c"
endwith
this.Requery()
You can assign all of these properties on the Property Sheet at design time:
this.rowsourcetype = 5
this.rowsource = "thisform.adata"
this.firstelement = 1
2) Encapsulate the array right into a subclass of the Listbox. This requires a little more front end work, but in the long run is better than option #1 because it's better OO.
3) Use the AddItem() and AddListItem() methods to populate the control, this can be a hassle when you are using more than 1 column.
>I am trying to input an array into a listbox, but I am failed. The data never be shown inside the listbox.
>
>Even I tried these codes in the listbox init event.
>DIMENSION adata(3)
>adata[1]="a"
>adata[2]="b"
>adata[3]="c"
>this.rowsourcetype = 5
>this.rowsource = "adata"
>this.firstelement = 1
>
>What's wrong on my code?