Microsoft KB Archive/148998

= DOCERR: ListIndex (OutLine) Returns -1 If No Item Is Selected =

Article ID: 148998

Article Last Modified on 9/30/2003

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition
 * Microsoft Visual FoxPro 3.0b Standard Edition

-



This article was previously published under Q148998



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. It also says that the first index number that the ListIndex property can return is 1, which is also incorrect. The first index number that can be returned is 0.



MORE INFORMATION
The OutLine control is contained in the Msoutl32.ocx file 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 where 0 is returned if no item is selected. This occurs because arrays in FoxPro start at 1.

Steps to Illustrate Behavior
 Create a new form, and add a OLE Container control by moving 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 the ControlSource property, type:

THISFORM.OLECONTROL1.LISTINDEX

  In the Click event of the OutLine control, place the following code: THISFORM.TEXT1.VALUE = THISFORM.OLECONTROL1.LISTINDEX  Run the form. Note that the text box displays -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.</ol>

Additional query words: VFoxWin

Keywords: KB148998

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.