>How can I add an array to a listbox in class designer as a property? I use >WinXP, VFP 7. ...
First, you can't add properties to VFP baseclasses (is that what you were trying to do?). So, first thing you need to do is create a subclass of the listbox itself. Several ways to do that. One is to go to your Classes Tab of the project, click 'inside' one of the class libraries there and do:
- Click the 'New' button - type in a class name, e.g. 'myList' - in the 'Based On' drop down, select 'ListBox' - Click OK
At that point you'll get a listbox on screen, which is named myList, and it will be contained in whatever class library you were in when you started the procedure (if you have no class libraries, you'll need to create one to contain you listbox class).
When your mylist class is the active window, you can click on the 'Class' Menu option (top of screen), and bring up the Edit Property/Method window (sorta like a Form's Edit Property/Method windows). From there you can add properties and methods to your heart's content.
I would add a property, 'aData2Show[1]' - then, in the properties of the listbox, I'd set the .rowsourcetype to 5 (array), and the .rowsource property to 'THIS.aData2Show' Note: you would probably want to put some code in the Init event of the control to make sure the array .aData2Show has at least 1 item - maybe just blank. Otherwise, when you drop it on a Form, and you can't load data into it, you'll get a listbox with a ".F." as the only item. Some users might get offended at seeing this (aka what does that "F" stand for, huh? <g>).
Side note: when you add or remove items from the array at runtime, I'd recommend doing a "THIS.Requery()" - it helps with refreshing the display, etc of the control.
There are other ways to do the above in code, but that was the 'visual' route.
After you've got your baseclass listbox, you can drag and drop it onto forms (e.g. drag from the class tab onto an open form). You can also add it via code with the .addobject() method, and so on and so forth.
HTH, -Charlie
©2003 Charlie Coleman |