Wiki Home

List Box

Namespace: WIN_COM_API
The base control in VFP to display listboxes.

VFP 5.0 Bug
I just wrestled with this problem and thought I'd post the answer for the next guy.

Multi-select list box. Need to programmatically select the second item in the list when the form INITs. Putting ThisForm.ListBox.Selected(2) = .T. doesn't select it. Putting ThisForm.ListBox.ListIndex = 2 doesn't select it either. It puts a small dotted line around the second entry, but querying the selected property still shows false. The problem only occurs when you have a rowsource type other than 0. If you Add Item all the entries into the listbox it works fine. See the KB article below for the official workaround. I looked this up and found that it was a known bug in 3.0. See:
-- Marty Smith

It's a shame that using RowSources limit the functionality of this control. Using anything other than the AddItems method disables the Picture property of the List Box. This is a handy icon which you can place on ListItems under certain conditions. Tim Hustler
Aha! It's fixed in 6.0. Cool. -- Marty Smith
Selecting all items in List Box via code (VFP6.0) proved more of a challenge than I foresaw. There is some strange antagonism between Selected and Visible with which to contend. - Steven Blake
Normal Behavior: To select all items, user must manually select top item, scroll to bottom, then select last item while SHIFT key is pressed.
Observation 1: Although the .Selected property is accessed as an array, it does not accept a universal assignment. ( .Selected = .T. does nothing.)
Observation 2: For..Next loop offered very quick response when assigning .F. (deselect) to each .Selected element but crept when assigning .T.
Observation 3: Assigning .F. to .Visibility property of List Box provided just as quick response via For..Next loop when assigning .T. but .F. absolutely bombed (only top item deselected)
Workaround: See sample code List Box Items Select All for the fastest operation I could tuck into a method
Limitation: This speed up trick works for array RowSourceType; both alias and field types fail; have not experimented with others yet

09/27/2002 Steven Blake - My front end Microsoft?SQL Server?application (VFP6.0) had a List Box with the Multi Select Property set true. Once the user made selection(s), the joins on the local workstation took forever because several remote tables each had hundred thousand rows to retrieve. My solution was to utilize a SQL - Temporary Table.
Category VFP Controls
( Topic last updated: 2004.08.03 04:49:43 AM )