A medida que escribimos un texto para buscar, se filtra y se colorea el texto coincidente en los cada registro de la grilla. Este efecto se logra con las propiedades DynamicForeColor y DynamicFontBold de cada columna
LOCAL oForm oForm = NEWOBJECT("Form1") oForm.SHOW READ EVENTS RETURN DEFINE CLASS Form1 AS FORM HEIGHT = 390 WIDTH = 770 AUTOCENTER = .T. CAPTION = "Resultados de búsquedas claros" SHOWTIPS = .T. _cSearch = "" ADD OBJECT grid1 AS GRID WITH ; GRIDLINES = 0, HEIGHT = 328, LEFT = 10, TOP = 50, WIDTH = 750, ; GRIDLINES = 3, DELETEMARK = .F., GRIDLINECOLOR = RGB(192,192,192) ,; FONTNAME = "Tahoma", FONTSIZE = 8, READONLY = .T., ANCHOR = 15 ADD OBJECT label1 AS LABEL WITH ; TOP = 15, LEFT = 10, ; CAPTION = "Buscar", BACKSTYLE = 0 ADD OBJECT Text1 AS TEXTBOX WITH ; TOP = 10,LEFT = 55, HEIGHT = 23,WIDTH = 300, VALUE = "", ; TOOLTIPTEXT = "Comience a escribir para buscar los registros coincidentes. " + ; "Doble clic para borrar la búsqueda" PROCEDURE LOAD SET TALK OFF SET SAFETY OFF CLOSE DATABASES ALL SELECT company, contact, TITLE ; FROM (HOME(2)+"data\customer") ; WHERE .F. ; INTO CURSOR junk1 READWRITE ENDPROC PROCEDURE grid1.INIT WITH THIS .RECORDSOURCETYPE = 6 .RECORDSOURCE = "junk1" .Column1.DYNAMICFORECOLOR = "IIF(thisform._cSearch $ UPPER(company),RGB(220,0,0),RGB(0,0,0))" .Column2.DYNAMICFORECOLOR = "IIF(thisform._cSearch $ UPPER(contact),RGB(220,0,0),RGB(0,0,0))" .Column3.DYNAMICFORECOLOR = "IIF(thisform._cSearch $ UPPER(title),RGB(220,0,0),RGB(0,0,0))" .Column1.DYNAMICFONTBOLD = "IIF(thisform._cSearch $ UPPER(company),.T.,.F.)" .Column2.DYNAMICFONTBOLD = "IIF(thisform._cSearch $ UPPER(contact),.T.,.F.)" .Column3.DYNAMICFONTBOLD = "IIF(thisform._cSearch $ UPPER(title),.T.,.F.)" ENDWITH ENDPROC PROCEDURE Text1.DBLCLICK THIS.VALUE = "" ZAP IN junk1 THISFORM.grid1.REFRESH ENDPROC PROCEDURE Text1.INTERACTIVECHANGE LOCAL lcSearch lcSearch = UPPER(ALLTRIM(THIS.VALUE)) THISFORM._cSearch = m.lcSearch SELECT company, contact, TITLE ; FROM HOME(2)+"data\customer" ; WHERE UPPER(cust_id+company+contact+TITLE) LIKE "%"+m.lcSearch+"%" ; INTO CURSOR junk2 NOFILTER SELECT junk1 ZAP IN junk1 APPEND FROM DBF("Junk2") GO TOP THISFORM.grid1.REFRESH ENDPROC PROCEDURE DESTROY CLEAR EVENTS ENDPROC ENDDEFINE
Fuente: Sandstorm's Blog (Jun Tangunan, Cabanatuan, Philippines) 20 jun 2012
Excelente codigo; gracias a los de portalfox y al autor. Me sirve mucho
ResponderBorrarMuy bueno, lo adecué a una exploración detallada y funciona bien.
ResponderBorrarMuy buen código, gracias. Lo apliqué en una exploración y funciona.
ResponderBorrar