Microsoft KB Archive/161730

= BUG: Cannot Set the Selected Item for a List box in Form Init =

Article ID: 161730

Article Last Modified on 10/16/2002

-

APPLIES TO


 * Microsoft Visual FoxPro 5.0 Standard Edition
 * Microsoft Visual FoxPro 5.0a
 * Microsoft Visual FoxPro 6.0 Professional Edition

-



This article was previously published under Q161730



SYMPTOMS
In Visual FoxPro 3.0 the selected item in a list box can be initialized by placing the following code in the Form Init or the List box Init: THISFORM.List1.Selected(1) = .T. This does not work in Visual FoxPro version 5.0.



RESOLUTION
Place the following code in the Activate method of the form. The variable acts like a switch so that the code is executed only when the form is first instantiated. The variable switch should be added to the form as a property. Switch is initialized to false. IF !THISFORM.switch THISFORM.List1.Selected(1)= .T.    THISFORM.switch = .T.   ENDIF



STATUS
Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article.



Steps to Reproduce Behavior
 Create a form and add the employee table to the DataEnvironment. Add a list box to the form and set its RowSourceType to 6-Fields. Set its RowSource to employee.emp_id.  Place the following code in the Init of the form or the Init of the list box. THISFORM.List1.Selected(1)= .T.                       

Note that when the form is run, the first item is not selected.

Additional query words: kbvfp500 kbvfp500a kbvfp600

Keywords: kbbug kbprogramming KB161730

-

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

© Microsoft Corporation. All rights reserved.