Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Checkbox in a combobox
Message
De
02/10/2007 16:50:31
Mike Sue-Ping
Cambridge, Ontario, Canada
 
 
À
02/10/2007 15:29:04
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows XP
Database:
Visual FoxPro
Divers
Thread ID:
01258069
Message ID:
01258092
Vues:
12
>Hi everyone
>
>How can I insert a checkbox into a combobox?.
>
>I need the user could choose some item from a combobox, then some process based on the chosen item (on porpouse, it is possible to "filter at once" some records in a table based on the chosen items ?..)...
>
>Thanks in advance
>Carlos Burgos


Carlos,

Here is some code that I think I got from the UT. All credit goes to the original author:
PUBLIC frmBeerPicker
m.frmBeerPicker = CREATEOBJECT('f')
m.frmBeerPicker.show(1)

RETURN

**************************************************
*
DEFINE CLASS cbozbasecheckdropdown AS ComboBox

	style = 2
	rowsourcetype = 1
	PROTECTED zcmenuname
	zcmenuname = .F.
	*-- Separator character for multiple values
	zcandseparator = "|"
	*-- Required - the alias used to display the contents for the check combo
	zccheckrowsource = .F.
	Name = "cbozbasecheckdropdown"


	*-- Item in drop list has been checked/unchecked
	PROCEDURE zitemchecked
		*un/check the selected item in the menu
		SET MARK OF BAR BAR() OF (this.zcmenuname) TO !MRKBAR(this.zcmenuname, BAR())

		*Set our display value as all the items checked with a separator between each
		this.Value = ''
		LOCAL lnMarkCount
		m.lnMarkCount = 0
		FOR lni = 1 TO CNTBAR(this.zcmenuname)
			IF MRKBAR(this.zcmenuname, m.lni) = .T.
				m.lnMarkCount = m.lnMarkCount + 1
				this.Value = this.Value + IIF(!EMPTY(this.Value),this.zcandseparator,"") + PRMBAR(this.zcmenuname, m.lni)
			ENDIF
		ENDFOR
		IF m.lnMarkCount = 0
			this.Value = 'All'
		ENDIF

		this.ToolTipText = STRTRAN(this.Value, this.zcandseparator, " AND ")
	ENDPROC


	PROCEDURE Init
		this.zcmenuname = "mnu"+SYS(2015)
		DODEFAULT()
	ENDPROC


	PROCEDURE DropDown
		*Show popup menu
		NODEFAULT
		*Ensure the alias is defined as required
		IF USED(this.zccheckrowsource) AND !EMPTY(FIELD('zValue',this.zccheckrowsource))
			SELECT (this.zccheckrowsource)
		ELSE
			RETURN 
		ENDIF

		Thisform.ScaleMode = 0		&& Foxels
		LOCAL lnPosX, lnPosY
		m.lnPosX = This.Left&& + This.Width
		m.lnPosY = This.Top + This.Height
		Thisform.ScaleMode = 3          && Back to Pixels && 
		TRY
			CLEAR POPUPS (this.zcmenuname)
		CATCH
		ENDTRY

		*Create the menu
		DEFINE POPUP (this.zcmenuname) RELATIVE FROM m.lnPosY, m.lnPosX  MARGIN SCROLL
		LOCAL lni
		m.lni = 1
		*Define the menu's contents
		SCAN
			DEFINE BAR (m.lni) OF (this.zcmenuname) PROMPT ALLTRIM(zValue)
			m.lni = m.lni + 1 
		ENDSCAN

		*Based on our current display value (this.value) - re-check items in the menu so it gives the user the
		*feeling that the state of this control has not changed
		ALINES(arItems,this.Value,1,this.zcandseparator)
		FOR m.lni = 1 TO CNTBAR(this.zcmenuname)
			IF ASCAN(arItems, PRMBAR(this.zcmenuname, m.lni),1,ALEN(arItems,1),1, 6) <> 0
				SET MARK OF BAR (m.lni) OF (this.zcmenuname) TO .T.
			ENDIF
		ENDFOR

		*Define the handler for checking (this)
		PRIVATE poThisCheckCombo
		m.poThisCheckCombo = this
		ON SELECTION POPUP (this.zcmenuname) poThisCheckCombo.zItemChecked()
		ACTIVATE POPUP (this.zcmenuname)
	ENDPROC


	PROCEDURE Destroy
		IF VARTYPE(poThisCheckCombo) = "O"
			RELEASE poThisCheckCombo
		ENDIF

		DODEFAULT()
	ENDPROC


	PROCEDURE zreadme
		*AH Sep10'07
		*
		* A checkbox-type combobox
		* 
		* Todo for the developer:
		* The contents of the combo must be an alias named and set as this.zcCheckRowsource
		* The column to display the data in the alias must have a column of 'zValue'
	ENDPROC


ENDDEFINE
*
*-- EndDefine: cbozbasecheckdropdown
**************************************************

DEFINE CLASS f AS form


	Top = 0
	Left = 0
	Height = 181
	Width = 375
	DoCreate = .T.
	Caption = "Favorite Beer Picker"
	Name = "f"


	ADD OBJECT cbozbasecheckdropdown1 AS cbozbasecheckdropdown WITH ;
		Height = 24, ;
		Left = 12, ;
		Top = 48, ;
		Width = 168, ;
		Name = "Cbozbasecheckdropdown1", ;
		zccheckrowsource = "cBeer"


	ADD OBJECT label1 AS label WITH ;
		Caption = "Favorite Beer", ;
		Height = 17, ;
		Left = 12, ;
		Top = 24, ;
		Width = 96, ;
		Name = "Label1"


	ADD OBJECT label2 AS label WITH ;
		Caption = "You Chose", ;
		Height = 17, ;
		Left = 12, ;
		Top = 84, ;
		Width = 96, ;
		Name = "Label2"


	ADD OBJECT label3 AS label WITH ;
		Caption = "", ;
		Height = 60, ;
		Left = 12, ;
		Top = 108, ;
		Width = 336, ;
		Name = "Label3", ;
		WordWrap = .T.


	PROCEDURE Init

		CREATE CURSOR cBeer (zValue C(50))
		INSERT INTO cBeer VALUES ("Lighthouse Race Rocks")
		INSERT INTO cBeer VALUES ("Alexander Keiths")
		INSERT INTO cBeer VALUES ("Pipers Pale Ale")
		INSERT INTO cBeer VALUES ("Moosehead")				
		INSERT INTO cBeer VALUES ("Fat Cat IPA")
		INSERT INTO cBeer VALUES ("Sleemans Honey Brown")				
	ENDPROC

	PROCEDURE cbozbasecheckdropdown1.zItemChecked
		cbozbasecheckdropdown::zItemChecked()
		this.parent.label3.Caption = STRTRAN(this.Value, this.zcandseparator, " AND ")
ENDDEFINE
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform