Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Listbox programmatically select & highlight
Message
 
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Network:
Windows 2003 Server
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01515590
Message ID:
01516376
Views:
57
>>>>Try doing it after the form is activated.
>>>
>>>Naomi,
>>>
>>>Thanks for your suggestion. I just moved the code that selects items in the listbox into the Activate method.
>>>
>>>Same result: items are selected, but they are not highlighted.
>>>
>>>Jim
>>
>>Hmm.
>>
>>I remember I worked on this problem (with my then colleague Mike Asherman) almost 10 years ago. There was some trick employed (like using Listbox when or Click method), but I don't recall right now details and wonder if I can find the relevant code.
>>
>>However, I do have a class posted in Downloads section here that I think was based on that listbox with saved selections (although may be the class I posted is grid's modification instead).
>>
>>UPDATE. Looks like I only posted the multi-select grid version of the class and never posted the listbox based version (which was chiefly designed by Mike)
>
>Naomi,
>
>I have just added code at the end of the form's refresh method to lbSetFocus. and added code in the listbox Whenmethod to select items in the listbox. Running under the debugger, I can see that the items get highlighted as they get selected, however, when I leave the When method, the highlighting goes away.
>
>Jim

I think you're lucky. I was just searching my library of controls from quite a recent job and I found that I do have a class there that resembles the original class created by Mike Asherman and enhanced by me.

Here is a List.Refresh method of this class:
********************************************************************
*  Description.......: List1.Refresh()
*  Calling Samples...:
*  Parameter List....:
*  Created by........: MDA
*  Modified by.......: Nadya Nosonovsky 01/18/2000 10:47:56 AM
********************************************************************
* 8/4/99: support pseudo-disablement of listbox.
*	Adapted from preliminary logic for handling the Counties listbox.
* 8/5/99: use alternate color (red) to distinguish exclusion from selection (blue).
* maintain pseudo-disablement of the listbox, even if parent.setall(...) disabled it
with this        
	if .parent.parent.visible && don't need to refresh if it's invisible	    
		.enabled = .t.		&& always keep the listbox actually enabled       
  
* fake up disablement of listbox so as to keep selections visible
		if .parent.enabled										&& parent container is enabled
* use default colors (I included all for clarity, but only two of these really change)
*!*	this.ItemBackColor = rgb(255,255,255)					&& white
			.itemforecolor = rgb(0,0,0)							&& black
			.selecteditembackcolor = ;
				iif(.parent.check1.value=1, rgb(128,0,0), rgb(0,0,128))	&& dark red or blue

		else														&& parent container is disabled
* use pseudo-disabled colors for the listbox
*!*	this.ItemBackColor = rgb(255,255,255)					&& white
			.itemforecolor = rgb(128,128,128)					&& gray
			.selecteditembackcolor = ;
				iif(.parent.check1.value=1, rgb(255,128,128), rgb(128,128,255))	&& light red or blue
*!*	this.SelectedItemForeColor = rgb(255,255,255) 			&& white
		endif
		dodefault()
	endif
endwith
When method of the class only seems to have this code:
********************************************************************
*  Description.......: List1.When()
*  Calling Samples...:
*  Parameter List....:
*  Created by........: MDA
*  Modified by.......: Nadya Nosonovsky 03/15/2000 01:06:07 PM
********************************************************************
* 8/4/99: keep Clear button disabled if list is already cleared.
*	Adapted from preliminary logic for handling the Counties listbox.
* 8/7/99: added tie-in to new cascade method, for propagating changes as necessary.
* 9/26/99: trying to debug problems with failure to detect un-selection in some cases.
*
* Unfortunately, there's no way to be more selective about this logic, because
* VFP doesn't trigger any more specific event when an item is selected or unselected.

* force related refreshes to handle changes in the choice of selections
with this.parent.parent
		this.parent.Command1.refresh()		&& handles button enablement/disablement
		if .HasDependents
			.Cascade()	&& force re-init of any dependent controls
		endif
endwith
so it doesn't seem to be relevant.

I see that comments are the original Mike's comments.

Apparently in our case the selections were saved and preserved and it all worked well.
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform