Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Dynamic Tooltip for each Grid Cell
Message
De
29/07/2010 16:11:47
Scott Butts
Ims Specialty Services
Twin Falls, Idaho, États-Unis
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01381430
Message ID:
01474513
Vues:
131
J'aime (1)
>>>Is there a way to do a dymanic tooltip for each cell of a grid? I tried the search and it kept saying to narrow the search down. Any help would be appreciated.
>>>
>>>Thanks
>>>Scott
>>
>>Figured it out using Access methods.
>
>Hi Scott,
>
>Can you post the detailed solution if it works? I retrieve a field of type text from SQL database. I want to show the first 200 characters in a grid and a nice tooltip with more information.


Here is what I came up with, it works GREAT!
**************************************************
*-- Class:        grdtxtfld
*-- ParentClass:  textbox
*-- BaseClass:    textbox
*-- Time Stamp:   02/12/09 02:31:02 PM
*
DEFINE CLASS grdtxtfld AS textbox


	BorderStyle = 0
	Height = 23
	Margin = 0
	MousePointer = 1
	SpecialEffect = 1
	Width = 100
	Name = "grdtxtfld"


	PROCEDURE RightClick
		THIS.PARENT.PARENT.RIGHTCLICK()
	ENDPROC


	PROCEDURE KeyPress
		LPARAMETERS nKeyCode, nShiftAltCtrl

		IF nKeyCode = 13
			THIS.PARENT.PARENT.DBLCLICK()
		ENDIF
	ENDPROC


	PROCEDURE Click
		THIS.PARENT.PARENT.CLICK()
	ENDPROC


	PROCEDURE DblClick
		THIS.PARENT.PARENT.DBLCLICK()
	ENDPROC


	PROCEDURE MouseDown
		LPARAMETERS nButton, nShift, nXCoord, nYCoord

		THIS.PARENT.PARENT.MOUSEDOWN(nButton,nShift,nXCoord,nYCoord)
	ENDPROC


ENDDEFINE
*
*-- EndDefine: grdtxtfld
**************************************************

**************************************************
*-- Class:        grdtxtfldtooltip 
*-- ParentClass:  grdtxtfld 
*-- BaseClass:    textbox
*-- Time Stamp:   02/17/09 12:55:03 PM
*
DEFINE CLASS grdtxtfldtooltip AS grdtxtfld


	lshowcontentsastip = .T.
	cdynamictooltipmethod = ""
	Name = "grdtxtfldtooltip"


	PROCEDURE tooltiptext_access
		LOCAL loGrid AS GRID, lcDBF AS STRING, lcFld AS STRING, lnRecNum AS INTEGER
		LOCAL lnX AS INTEGER, lnY AS INTEGER, lcTipText AS STRING
		LOCAL lcDynamicToolTipMethod AS STRING
		PRIVATE lnWhere AS INTEGER, lnRelRow AS INTEGER, lnRelCol AS INTEGER

		LOCAL ARRAY aMouseInfo[1]

		lcTipText = THIS.TOOLTIPTEXT													&& Default to the currently assigned ToolTip Text
		DO CASE																			&& Determine the Requested type of tip
		CASE THIS.lShowContentsAsTip													&& If Text Box contents, return Value property
			lcTipText = TRANSFORM(THIS.VALUE)
		CASE !(EMPTY(THIS.cDynamicToolTipMethod))										&& If there is a DynamicToolTipMethod value
			loGrid 		= THIS.PARENT.PARENT											&& Determine all the required paramaeters to
			lcDBF 		= JUSTSTEM(THIS.CONTROLSOURCE)									&& pass to that method
			lcFld 		= JUSTEXT(THIS.CONTROLSOURCE)
			lnRecNum 	= RECNO(JUSTSTEM(THIS.CONTROLSOURCE))

			AMOUSEOBJ(aMouseInfo,1)														&& Determine Mouse position with AMOUSEOBJ
			lnX = aMouseInfo[3]															&& required for the call to GridHitTest
			lnY = aMouseInfo[4]

			STORE 0 TO lnWhere, lnRelRow, lnRelCol										&& GridHitTest will determine Relative Row\Column
			loGrid.GRIDHITTEST(lnX, lnY, @lnWhere, @lnRelRow, @lnRelCol)

			lcDynamicToolTipMethod = CHRTRAN(THIS.cDynamicToolTipMethod,"()","")		&& Formate command str for evaluation
		*!* Parameters needed for the call to the DynamicToolTipMethod
		*!*	vcDBF as String, vcFld as String, vnRecNum as Integer, vnRelCol as Integer
		*!* Sample Return Statement
		*!*	RETURN "DBF: " + vcDBF + " Field: " + vcFld + " Record #: " + ;
		*!*		TRANSFORM(vnRecNum) + " Relative Column: " + TRANSFORM(vnRelCol)

			lcCmd = lcDynamicToolTipMethod + [("] + lcDBF + [","] + ;
				lcFld + [",] + TRANSFORM(lnRecNum) + [,] + TRANSFORM(lnRelCol) + [)]

			TRY																			&& Use Try Catch to avoid errors
				lcTipText = EVALUATE(lcCmd)
			CATCH TO loException
				lcTipText = loException.MESSAGE
			ENDTRY
		OTHERWISE
		* ToolTip Text is origianl ToolTip of control
		ENDCASE

		RETURN lcTipText
	ENDPROC


ENDDEFINE
*
*-- EndDefine: grdtxtfldtooltip
**************************************************
You will need to RemoveObj the text field from the grid control and add the GrdTxtFldToolTip text object in its place, also make sure that you setup the cDynamicToolTipMethod property and code it to return a string.

Let me know how this works for you.

Scott
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform