Microsoft KB Archive/148861

= Microsoft Knowledge Base =

DOCERR: ListIndex (OutLine) Returns -1 If No Item Is Selected
Last reviewed: March 28, 1996

Article ID: Q148861

The information in this article applies to:


 * Microsoft Visual FoxPro for Windows, versions 3.0 and 3.0b

SUMMARY
Visual FoxPro Help says that the return value for the ListIndex (OutLine Control) Property is 0 if no item is selected. This is incorrect. The value returned if no item is selected is -1.

Also, Visual FoxPro Help says that the first index number that the ListIndex property can return is 1, which is incorrect. The first index number that can be returned is 0.

MORE INFORMATION
The OutLine control is contained in the Msoutl32.ocx file that is located in the Windows\System subdirectory. Because .ocx files are written in the C language, the arrays they use start at zero. Therefore, the array that holds the values in the OutLine control that the ListIndex property references starts at zero. This referencing is different from the ListIndex property for a combo or list box which returns 0 if no item is selected because arrays in FoxPro start at 1.

Step to Reproduce Behavior
 Create a new form, and add a OLE Container control by dragging it from the Form Controls toolbar to the form. When the Insert Object dialog box appears, click Insert Control, and select the OutLine Control from the Control Type list box.  Add the following code to the Init event of the OutLine control: THIS.ADDITEM("Colors",0) && This places the word Colors in the THIS.ADDITEM("Red",1)   && first element of the array followed THIS.ADDITEM("Blue",2)  && by Red, Blue,and Green to give THIS.ADDITEM("Green",3) && a total of four elements in the array && to be displayed in the Outline && control.

THIS.INDENT(0) = 1      && This gives the word Colors an   THIS.INDENT(1) = 2       && indention level of 1. These lines THIS.INDENT(2) = 2      && indent the words Red, Blue, and THIS.INDENT(3) = 2      && Green under the word Colors && with an indention level of 2.   Place a text box on the form. In its ControlSource property, type: THISFORM.OLECONTROL1.LISTINDEX   In the Click event of the Outline control, place this code: THISFORM.TEXT1.VALUE = THISFORM.OLECONTROL1.LISTINDEX  Run the form. Note that the text box displays a -1. After you click the word Colors, the value of the text box changes to 0. Click the plus sign to the left of the word Colors, and then click any item under it. The text box displays the ListIndex value of whatever item is selected. Remember that the text box will show a number that is one less than the position of the item selected in the Outline control. That is because the first item's array element number has a value of 0, the second item is 1, the third item is 2, and so on.