Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Can I detect the user has selected in a multiselect List
Message
 
 
To
23/05/2001 14:17:24
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
00510516
Message ID:
00510526
Views:
14
>Hi, all!
>
>Here is my problem:
>
>I have a multiselect listbox on a form. There is also a command button on the form. The command button should only be enabled if two or more list items are selected.
>
>Is there any event which fires as list items are selected/unselected?
>
>I tried putting some code in the mousedown/mouseup events. This works unless the user uses the keyboard to select items.
>
>I also tried creating a custom listbox class, with a selected_assign() method. This method doesn't seem to ever fire. I was hoping that as the selected() property of the listbox changed, the assign method would fire. But it doesn't.
>
>Any ideas?
>
>- George

George,

I have such class designed. In the download section here there is an example of such class, but using multiselect grid by Cetin Basoz. I have the same class with listbox too. Listbox itself has three coded methods: Click
********************************************************************
*  Description.......: List1.Click()
*  Calling Samples...: 
*  Parameter List....: 
*  Created by........: MDA 
*  Modified by.......: Nadya Nosonovsky 03/14/2000 05:40:14 PM
********************************************************************
* 9/26/99: added refresh/cascade logic here, because the When & GotFocus events don't see
*	certain changes, e.g. some cases of unselecting a previously selected list item.
*	Use of LostFocus helped, but the effect is delayed until user changes focus to another
*	control, so it's still not entirely satisfactory.
*
* Note that we may be refreshing more than necessary in most cases, but I'm trying to
* fix problems with cases that are otherwise missed altogether. Further optimization can wait.
*this.parent.parent.AllowWhen=.t.
this.when()		&& invoke the same logic used by When, but after change becomes visible
When event:
********************************************************************
*  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 btc_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 .HasDependants
			.btc_cascade()	&& force re-init of any dependent controls
		endif
endwith
It also has custom refresh method, but it doesn't relevant here.

Basically, once I selected an item, the Clear button becomes enabled. Otherwise it's disabled.

Clear button has this code in its refresh:
********************************************************************
*  Description.......: Command1.Refresh
*  Calling Samples...: 
*  Parameter List....: 
*  Created by........: MDA 
*  Modified by.......: Nadya Nosonovsky 01/18/2000 10:51:39 AM
********************************************************************
* 8/4/99: keep Clear button disabled if list is already cleared.
*	Adapted from preliminary logic for handling the Counties listbox.
if this.parent.parent.visible
		this.enabled = this.parent.enabled ;
               and (!empty(this.parent.parent.btc_itemlist()) or this.parent.parent.AllSelected)
endif
HTH
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform