Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Newbie observations on comboboxes...
Message
From
18/11/2006 11:50:55
 
 
To
18/11/2006 11:06:17
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Environment versions
Visual FoxPro:
VFP 6 SP5
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01170960
Message ID:
01170984
Views:
10
>I am just trying to get the native combobox to work in a more typical setting, say a dropdown list of part numbers and descriptions for several hundred items at most. Probably a pretty common scenario for invoices.
>
>So while the native combobox might hit some limitations with hundreds of thousands of rows, I am just trying "to walk before I run", and not taxing it at all.
>
>But its quirky behaviors make it pretty much useless, as I would be embarrassed to deliver an application with a dropdown that "works" like this one.
>
>I do appreciate the recommendation to try downloading an alternate combo class that someone has been kind enough to develop and share! It just frustrates me that after all the versions of VFP (3 thru 9), that such an important native class does not work as the masses would expect... And that I just happen to pick it on the very forst form I try to design as a newbie :(
>
>I wonder, has there ever been an enhancement request/bug report made to Microsoft to fix this issue? Does Microsoft VFP's developers ever communicate with this forum?
>
>
>
>
>>Frankly the combo box is not the greatest control. It's often abused. How do I put 400,000 customers in a combobox is a far too frequently asked question.
>>
>>I use Visual MaxFrame and it includes a textbox that replaces the combobox.
>>
>>There are combobox classes that can be found in the download section of the UT. Maybe one of them will work for you?


This object was designed in VFP 7 but with some tweaking should be able to do an incremental search just fine using the standard combobox. I took this code directly out of my VCX and dropped a few routines which you will need to add; maybe (restorewindowpos and savewindowpos). This works as a toolbar connecting to whatever form, and whatever object to perform the search. I use it to search in a grid of many records.
**************************************************
*-- Class:        ctbrlookup (e:\work\dcg\pvr\src\libs\pvr.vcx)
*-- ParentClass:  toolbar
*-- BaseClass:    toolbar
*-- Time Stamp:   02/19/04 01:50:02 AM
*
#INCLUDE "c:\...\include.h"
*
DEFINE CLASS ctbrlookup AS toolbar


	Caption = "Lookup List"
	Height = 28
	Left = 0
	Sizable = .F.
	Top = 0
	Width = 298
	ControlBox = .F.
	oparentform = .NULL.
	oparentobject = .NULL.
	Name = "ctbrlookup"
	nincseek = .F.
	ltimer = .F.

	*-- Works with the lErrorOverride.  If an error occurs this property will be true
	lerroroccurred = .F.

	*-- Set this property to true to override the form's error routine.  Set it back when you are done.  Sets the lErrorOccurred property if an error exists.
	lerroroverride = .F.


	ADD OBJECT cmblist AS combobox WITH ;
		FontName = "Arial", ;
		FontSize = 10, ;
		RowSourceType = 6, ;
		Height = 22, ;
		Left = 5, ;
		Style = 2, ;
		ToolTipText = "Type to search through list...", ;
		Top = 3, ;
		Width = 288, ;
		DisplayCount = 20, ;
		Name = "cmbList"


	ADD OBJECT tmrlookup AS timer WITH ;
		Top = 3, ;
		Left = 292, ;
		Height = 0, ;
		Width = 0, ;
		Name = "tmrLookup"


	PROCEDURE updatetoolbar
		* we need to attach this object to the datasession of the form
		* the toParentObject must have a controlsource: COLUMN
		LPARAMETERS toParentForm
		LOCAL lnSelect, lcAlias, lnRecno

		WITH THIS
			IF PARAMETERS() >= 1
				* We need to be able to see the tables from the Calling Form
				SET DATASESSION TO toParentForm.DATASESSIONID

				.oParentForm	= toParentForm

				lcAlias = ""
				lnRecno = 0
				IF TYPE("toParentForm.oColumn") = "O"
					.oParentObject	= toParentForm.oColumn
					lcAlias		= .oParentObject.ControlSource
					lcAlias		= SUBSTR(lcAlias, 1, AT(".", lcAlias)-1)
				ELSE
					.oParentObject	= NULL
				ENDIF

				IF !EMPTY(lcAlias) AND USED(lcAlias)
					SELECT (lcAlias)
					lnRecno		= IIF(BOF() OR EOF(), 0, RECNO())
				ELSE
					lcAlias		= ""
					lnRecno		= 0
				ENDIF
			ENDIF

			lnSelect	= SELECT()

			DO CASE
				CASE PARAMETERS() < 1 OR EMPTY(lcAlias) OR RECCOUNT(lcAlias) = 0
					.cmbList.ROWSOURCE	= NULL
					.cmbList.CONTROLSOURCE	= NULL
					.cmbList.VALUE		= NULL
					.cmbList.TOOLTIPTEXT	= "Lookup List is not available."

				*CASE UPPER(.oParentObject.Class) <> "CTXTORDERCOLUMN"
					* leave the object alone

				CASE PARAMETERS() >= 1 AND !EMPTY(lcAlias) AND ;
					VARTYPE(EVAL(toParentForm.oColumn.ControlSource)) = "C" AND ;
					INLIST(UPPER(ALLTRIM(.oParentObject.Class)), "CTXTORDERCOLUMN", "CEDTORDERCOLUMN")

					* numeric data types do not work so well
					.cmbList.FORMAT		= "!"
					.cmbList.ROWSOURCE	= .oParentObject.ControlSource
					.cmbList.CONTROLSOURCE	= .oParentObject.ControlSource
					.cmbList.VALUE		= EVAL(.oParentObject.ControlSource)
					.cmbList.TOOLTIPTEXT	= ""

					IF lnRecno > 0
						GOTO lnRecno
					ELSE
						GO TOP
					ENDIF
					.cmbList.REFRESH()

				OTHERWISE
					.cmbList.ROWSOURCE	= NULL
					.cmbList.CONTROLSOURCE	= NULL
					.cmbList.VALUE		= NULL
					.cmbList.TOOLTIPTEXT	= "Lookup List is not available for this datatype."
			ENDCASE

		ENDWITH

		SELECT (lnSelect)
	ENDPROC


	PROCEDURE Init
		DODEFAULT()

		* Restore the toolbar's position
		*IF !THIS.RestoreWindowPos()
			* Default is to dock toolbar at top
			THIS.DOCK(TOOL_TOP)
		*ENDIF
	ENDPROC


	PROCEDURE Destroy
		* Save the toolbar's position
		*THIS.SaveWindowPos()
		* Make the toolbar disappear faster
		THIS.ENABLED = .F.
	ENDPROC


	PROCEDURE cmblist.KeyPress
		LPARAMETERS nKeyCode, nShiftAltCtrl

		* every keypress will reset the timer
		This.Parent.tmrLookup.Reset()
	ENDPROC


	PROCEDURE cmblist.GotFocus
		DODEFAULT()

		WITH THIS.Parent
			.nIncSeek	= _INCSEEK
			_INCSEEK	= .75

			* enable the timer - milliseconds
			.tmrLookup.Interval	= _INCSEEK * 1000
		ENDWITH
	ENDPROC


	PROCEDURE cmblist.LostFocus
		WITH THIS.Parent
			* disable the timer
			.tmrLookup.Interval	= 0
			_INCSEEK		= .nIncSeek
		ENDWITH

		DODEFAULT()
	ENDPROC


	PROCEDURE cmblist.InteractiveChange
		WITH THIS.Parent
			* this will wait for _INCSEEK time before processing
			.tmrLookup.Reset()

			DODEFAULT()

			.lTimer	= .T.
		ENDWITH
	ENDPROC


	PROCEDURE tmrlookup.Timer
		LOCAL lcBaseClass, llLockScreen, lnTimer

		WITH THIS.PARENT
			* only process when we are asked to by the LookUp
			IF .lTimer AND !CHRSAW()
				* turn off the timer while processing
				lnTimer		= THIS.Interval
				THIS.Interval	= 0

				.lTimer		= .F.
				llLockScreen	= .oParentForm.LOCKSCREEN
				lcBaseClass	= UPPER(.oParentObject.BASECLASS)
				DO CASE
					CASE lcBaseClass == "COLUMN"
						* point to the grid
						WITH .oParentObject.PARENT
							.AFTERROWCOLCHANGE(.ACTIVECOLUMN)
						ENDWITH
				ENDCASE
				.oParentForm.LOCKSCREEN	= llLockScreen

				* turn on the timer when completed
				THIS.Interval	= lnTimer
			ENDIF
		ENDWITH
	ENDPROC


ENDDEFINE
*
*-- EndDefine: ctbrlookup
**************************************************
Gordon de Rouyan
DC&G Consulting
Edmonton, Alberta
Email: derouyag@shaw.ca
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform