Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Programmatically set multilist default choices

Status
Not open for further replies.

clueman

Technical User
Oct 23, 2006
2
US
Hi Guys,

There must be a "gotcha" in this that's really gettin' me. I need to programmatically pre-select 2-5 members of a group of about 20 default choices in a MultiSelect ListBox. If the following code is placed in the INIT of the multiselect list, it fails. But if it is placed in the CLICK of a CommandButton it works just fine (after the Form is constructed and visible).
Code:
WITH THISFORM.list1
    FOR i = 1 TO .LISTCOUNT
	IF INLIST(i,1,2,4,7)
	    .SELECTED(i) = .T.
	ENDIF
    NEXT
ENDWITH
The failed result appears as a dotted line drawn around only the last member of the default list (in this example, 7); no highlights; all list members test False on Selected().

The normal result (done by CommandButton code) highlights all defaults correctly.

I have tried: 1) Placing code in the Form.Init event (to fire later); 2) Setting focus to both off and on the ListBox before running the default code. Neither works; 3) Setting ScreenLock .T. Nada for all of these tries.

What am I missing here?

TIA

 
It works for me, so there must be something else going on here. Have you tried tracing the code or setting a breakpoint on the Selected value of an item?

Tamar
 
Thanks very much for your reply, Tamar.

No, I hadn't traced the code; but I did just now when I got your reply. And the results are even more perplexing.

With the code in the INIT event of the ListBox, the pre-set values remain TRUE throughout the entire procedure. But all items were False by the time the List visualized.

So I next placed the code in the INIT event of the Form(to fire later). Same result there. Values TRUE at end of loop, but FALSE when visualized.

So I next tried placing the code in the ACTIVATE of the Form. But they were again FALSE upon visualization. Then when I placed a SET STEP ON in Activate, things really got interesting!! Apparently the Debugger doesn't like the Activate event, cuz it stepped through it OK, but wouldn't step out of it and into the form visualizing. Froze and had to kill Foxpro.

But stepping through the code in Activate, it likewise properly set the requested items to TRUE while at the event.

Weird! Any ideas?

At this point it would be no big deal to require the user to set the defaults with a single CommandButton click, which works quite readily. But I'm sure you get the picture that now it's more a matter of wondering what the heck is going on here.

Thanks again for any ideas.
 
I think you've got code somewhere that's manipulating the Value of the listbox. That would have the effect of deselecting the items.

Try putting the listbox value in the Watch window and setting a breakpoint on it.

Tamar
 
I need to programmatically pre-select 2-5 members of a group of about 20 default choices in a MultiSelect ListBox. If the following code is placed in the INIT of the multiselect list, it fails.

You do not say which version of VFP you are using, but from what Tamar is saying, this one is apparently fixed in version 9:

BUG: Using Selected Method in Init Event Does Not Work
PSS ID Number: 177340

Article Last Modified on 12/11/1999


--------------------------------------------------------------------------------
The information in this article applies to:


Microsoft Visual FoxPro for Windows 5.0
Microsoft Visual FoxPro for Windows 5.0a
Microsoft Visual FoxPro for Windows 6.0

--------------------------------------------------------------------------------

This article was previously published under Q177340
SYMPTOMS

In Visual FoxPro versions 5.x, programmatically using the Selected method to select an item in a list box does not work in the Init method of a list box or a form.

Marcia G. Akins
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top