how to catch mouse event in a grid ?

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

User avatar
danielmaximiliano
Posts: 2611
Joined: Fri Apr 09, 2010 4:53 pm
Location: Argentina
Contact:

Re: How to catch mouse event in a grid ?

Post by danielmaximiliano »

Muy bueno !!!! ,,
gracias por compartir
*´¨)
¸.·´¸.·*´¨) ¸.·*¨)
(¸.·´. (¸.·` *
.·`. Harbour/HMG : It's magic !
(¸.·``··*

Saludos / Regards
DaNiElMaXiMiLiAnO

Whatsapp. := +54901169026142
Telegram Name := DaNiElMaXiMiLiAnO
Javier Tovar
Posts: 1275
Joined: Tue Sep 03, 2013 4:22 am
Location: Tecámac, México

Re: How to catch mouse event in a grid ?

Post by Javier Tovar »

Bien! Pablo César!

Saludos
User avatar
mol
Posts: 3718
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: how to catch mouse event in a grid ?

Post by mol »

How can I set different tooltip for every row?
Is it the way to detect row pointed by mouse hovering and change tooltip depends on pointed (without clicking) grid cell?
Did anybody realized this?
edk
Posts: 909
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: how to catch mouse event in a grid ?

Post by edk »

mol wrote: Sat Jan 19, 2019 11:14 am How can I set different tooltip for every row?
Is it the way to detect row pointed by mouse hovering and change tooltip depends on pointed (without clicking) grid cell?
Did anybody realized this?
I did not do it before, but I made this code especially for you ;) :

Code: Select all

#include "hmg.ch"

Function Main
Local aRows [20] [3]

	DEFINE WINDOW Form_1 ;
		AT 0,0 ;
		WIDTH 800 ;
		HEIGHT 550 ;
		TITLE 'Hello World!' ;
		MAIN 

		aRows [1]	:= {'Simpson','Homer','555-5555'}
		aRows [2]	:= {'Mulder','Fox','324-6432'} 
		aRows [3]	:= {'Smart','Max','432-5892'} 
		aRows [4]	:= {'Grillo','Pepe','894-2332'} 
		aRows [5]	:= {'Kirk','James','346-9873'} 
		aRows [6]	:= {'Barriga','Carlos','394-9654'} 
		aRows [7]	:= {'Flanders','Ned','435-3211'} 
		aRows [8]	:= {'Smith','John','123-1234'} 
		aRows [9]	:= {'Pedemonti','Flavio','000-0000'} 
		aRows [10]	:= {'Gomez','Juan','583-4832'} 
		aRows [11]	:= {'Fernandez','Raul','321-4332'} 
		aRows [12]	:= {'Borges','Javier','326-9430'} 
		aRows [13]	:= {'Alvarez','Alberto','543-7898'} 
		aRows [14]	:= {'Gonzalez','Ambo','437-8473'} 
		aRows [15]	:= {'Batistuta','Gol','485-2843'} 
		aRows [16]	:= {'Vinazzi','Amigo','394-5983'} 
		aRows [17]	:= {'Pedemonti','Flavio','534-7984'} 
		aRows [18]	:= {'Samarbide','Armando','854-7873'} 
		aRows [19]	:= {'Pradon','Alejandra','???-????'} 
		aRows [20]	:= {'Reyes','Monica','432-5836'} 

		@ 10,10 GRID Grid_1 ;
			WIDTH 760 ;
			HEIGHT 240 ;
			HEADERS {'Last Name','First Name','Phone'} ;
			WIDTHS {140,140,140};
			ITEMS aRows ;
			VALUE {1,1} ;
			TOOLTIP 'Editable Grid Control' ;
			EDIT ;
	                JUSTIFY { GRID_JTFY_CENTER,GRID_JTFY_RIGHT, GRID_JTFY_RIGHT } ;
			CELLNAVIGATION 


		@ 250,10 GRID Grid_2 ;
			WIDTH 760 ;
			HEIGHT 240 ;
			HEADERS {'Last Name','First Name','Phone'} ;
			WIDTHS {140,140,140};
			ITEMS aRows ;
			VALUE 1 EDIT ;
			TOOLTIP 'Editable Grid Control' ;
			ON HEADCLICK { {||MsgInfo('Click 1')} , {||MsgInfo('Click 2')} , {||MsgInfo('Click 3')} } ;
                	JUSTIFY { GRID_JTFY_LEFT,GRID_JTFY_CENTER, GRID_JTFY_CENTER } 

		CREATE EVENT PROCNAME Grid_ToolTip()
					
					
	END WINDOW

	CENTER WINDOW Form_1

	ACTIVATE WINDOW Form_1

Return

FUNCTION Grid_ToolTip()
LOCAL nHWnd := EventHWND(), aCellMouseOver, cCtrlName:="", cFormName:=""
LOCAL nIndex := GetControlIndexByHandle ( nHWnd )
LOCAL cCtrlType := IF( nIndex > 0, GetControlTypeByIndex (nIndex) , "") 
STATIC aTT := {0,0}

IF cCtrlType == 'GRID'

	GetControlNameByHandle (nHWnd, @cCtrlName, @cFormName)

	aCellMouseOver := ListView_HitTest ( nHWnd , GetCursorRow() - GetWindowRow ( nHWnd )  , GetCursorCol() - GetWindowCol ( nHWnd ) )
	
	IF aTT [1] # aCellMouseOver [1] .OR. aTT [2] # aCellMouseOver [2]
		aTT [1] := aCellMouseOver [1]
		aTT [2] := aCellMouseOver [2]
		IF aCellMouseOver [1] = 0 .AND. aCellMouseOver [2] = 0
			SetProperty( cFormName, cCtrlName, "ToolTip", "")
		ELSE
			SetProperty( cFormName, cCtrlName, "ToolTip", "ToolTip for Row=" + Alltrim(HB_ValToStr( aCellMouseOver [1] )) + " Col=" + Alltrim(HB_ValToStr( aCellMouseOver [2] )) + " Value=" + GetProperty (cFormName, cCtrlName, "CellEx", aCellMouseOver [1], aCellMouseOver [2] ) )
		ENDIF
	ENDIF

ENDIF

RETURN Nil
There is a different ToolTip for each cell, but you'll easy manage to get this effect for a different row ;) .
Zimbo
Posts: 56
Joined: Mon Nov 05, 2012 1:28 pm
Location: Scotland
Contact:

Re: how to catch mouse event in a grid ?

Post by Zimbo »

Thanks for sharing. I am having problems catching keyboard events (up, down etc). I need to refresh data outside of a grid when the user presses up or down but its not working. It DOES work if the user clicks on a different row in the grid!!

This example might help me solve the problem (with up, down arrow etc).

Z
User avatar
mol
Posts: 3718
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: how to catch mouse event in a grid ?

Post by mol »

Changing tooltip for every row and column works perfect.
But now, I need to change fontname and fontcolor depend on column number.
I/'m trying code

Code: Select all

		aFontWeather:= ARRAY FONT "Weather" SIZE 28
		SET TOOLTIPCUSTOMDRAW CONTROL GRID_Utargi OF FORM_Utarg FORECOLOR {0,0,128}  ARRAYFONT aFontWeather BALLOON .T. TITLE "WEATHER"
But it works only for first use.
I don't see any error in this code.
Can somebody
edk
Posts: 909
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: how to catch mouse event in a grid ?

Post by edk »

U mnie działa, włączyłeś SET TOOLTIPCUSTOMDRAW ON ?
Na moim Win 10 nie reaguje na FORECOLOR :?

It works for me, did you activate SET TOOLTIP CUSTOM DRAW ON?
On my Win 10 it does not respond to FORECOLOR :?

Code: Select all

#include "hmg.ch"

Function Main
Local aRows [20] [3]

SET TOOLTIPCUSTOMDRAW ON

	DEFINE WINDOW Form_1 ;
		AT 0,0 ;
		WIDTH 800 ;
		HEIGHT 550 ;
		TITLE 'Hello World!' ;
		MAIN 

		aRows [1]	:= {'Simpson','Homer','555-5555'}
		aRows [2]	:= {'Mulder','Fox','324-6432'} 
		aRows [3]	:= {'Smart','Max','432-5892'} 
		aRows [4]	:= {'Grillo','Pepe','894-2332'} 
		aRows [5]	:= {'Kirk','James','346-9873'} 
		aRows [6]	:= {'Barriga','Carlos','394-9654'} 
		aRows [7]	:= {'Flanders','Ned','435-3211'} 
		aRows [8]	:= {'Smith','John','123-1234'} 
		aRows [9]	:= {'Pedemonti','Flavio','000-0000'} 
		aRows [10]	:= {'Gomez','Juan','583-4832'} 
		aRows [11]	:= {'Fernandez','Raul','321-4332'} 
		aRows [12]	:= {'Borges','Javier','326-9430'} 
		aRows [13]	:= {'Alvarez','Alberto','543-7898'} 
		aRows [14]	:= {'Gonzalez','Ambo','437-8473'} 
		aRows [15]	:= {'Batistuta','Gol','485-2843'} 
		aRows [16]	:= {'Vinazzi','Amigo','394-5983'} 
		aRows [17]	:= {'Pedemonti','Flavio','534-7984'} 
		aRows [18]	:= {'Samarbide','Armando','854-7873'} 
		aRows [19]	:= {'Pradon','Alejandra','???-????'} 
		aRows [20]	:= {'Reyes','Monica','432-5836'} 

		@ 10,10 GRID Grid_1 ;
			WIDTH 760 ;
			HEIGHT 240 ;
			HEADERS {'Last Name','First Name','Phone'} ;
			WIDTHS {140,140,140};
			ITEMS aRows ;
			VALUE {1,1} ;
			TOOLTIP 'Editable Grid Control' ;
			EDIT ;
	                JUSTIFY { GRID_JTFY_CENTER,GRID_JTFY_RIGHT, GRID_JTFY_RIGHT } ;
			CELLNAVIGATION 


		@ 250,10 GRID Grid_2 ;
			WIDTH 760 ;
			HEIGHT 240 ;
			HEADERS {'Last Name','First Name','Phone'} ;
			WIDTHS {140,140,140};
			ITEMS aRows ;
			VALUE 1 EDIT ;
			TOOLTIP 'Editable Grid Control' ;
			ON HEADCLICK { {||MsgInfo('Click 1')} , {||MsgInfo('Click 2')} , {||MsgInfo('Click 3')} } ;
                	JUSTIFY { GRID_JTFY_LEFT,GRID_JTFY_CENTER, GRID_JTFY_CENTER }
                	
   		CREATE EVENT PROCNAME Grid_ToolTip()
					
					
	END WINDOW

	CENTER WINDOW Form_1

	ACTIVATE WINDOW Form_1

Return

FUNCTION Grid_ToolTip()
LOCAL nHWnd := EventHWND(), aCellMouseOver, cCtrlName:="", cFormName:=""
LOCAL nIndex := GetControlIndexByHandle ( nHWnd )
LOCAL cCtrlType := IF( nIndex > 0, GetControlTypeByIndex (nIndex) , "")
LOCAL aFontList := { "Arial", "Juice ITC", "Webdings" }
LOCAL aFontWeather, aForeColor

STATIC aTT := {0,0}

IF cCtrlType == 'GRID'

	GetControlNameByHandle (nHWnd, @cCtrlName, @cFormName)

	aCellMouseOver := ListView_HitTest ( nHWnd , GetCursorRow() - GetWindowRow ( nHWnd )  , GetCursorCol() - GetWindowCol ( nHWnd ) )
	
	IF aTT [1] # aCellMouseOver [1] .OR. aTT [2] # aCellMouseOver [2]
		aTT [1] := aCellMouseOver [1]
		aTT [2] := aCellMouseOver [2]
		
		IF aCellMouseOver [1] = 0 .AND. aCellMouseOver [2] = 0
			SetProperty( cFormName, cCtrlName, "ToolTip", "")
		ELSE
		
			aFontWeather:= ARRAY FONT aFontList [ aCellMouseOver [2] ] SIZE aCellMouseOver [1] * 5
			//aForeColor := { 0, aCellMouseOver [1] * 8, aCellMouseOver [2] * 64 }
			aForeColor := { 128, 0, 0 }
			SET TOOLTIPCUSTOMDRAW CONTROL &cCtrlName OF &cFormName FORECOLOR aForeColor ARRAYFONT aFontWeather BALLOON .T. TITLE "WEATHER" ICON aCellMouseOver [2]
		
			SetProperty( cFormName, cCtrlName, "ToolTip", "ToolTip for Row=" + Alltrim(HB_ValToStr( aCellMouseOver [1] )) + " Col=" + Alltrim(HB_ValToStr( aCellMouseOver [2] )) + " Value=" + GetProperty (cFormName, cCtrlName, "CellEx", aCellMouseOver [1], aCellMouseOver [2] ) )
		ENDIF
	ENDIF

ENDIF

RETURN Nil

tooltip.gif
tooltip.gif (88.78 KiB) Viewed 3117 times
User avatar
mol
Posts: 3718
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: how to catch mouse event in a grid ?

Post by mol »

I've realized my idea. It's really strange with forecolor. In one column is set to green, but when I change in another column, it becomes black :-D
When I set title to empty string, then body of tooltip becomes red :)

Code: Select all

if aKomorkaPodMysza [2] == GetProperty (cFormName, cCtrlName, "ColumnCount")-1	// uwagi
				SET TOOLTIPCUSTOMDRAW CONTROL G_Utargi OF OknoUtarg FORECOLOR {0,128,0}  ARRAYFONT aFontUwagi BALLOON .T. TITLE "" //ICON TOOLTIPICON_WARNING_LARGE
				SetProperty( cFormName, cCtrlName, "ToolTip",;
					GetProperty (cFormName, cCtrlName, "CellEx", aKomorkaPodMysza [1],;
					GetProperty (cFormName, cCtrlName, "ColumnCount")-1))
			elseif aKomorkaPodMysza [2] == GetProperty (cFormName, cCtrlName, "ColumnCount") // pogoda				
				SET TOOLTIPCUSTOMDRAW CONTROL G_Utargi OF OknoUtarg FORECOLOR {255,0,0}  ARRAYFONT aFontPogoda BALLOON .T. TITLE ""//POGODA" //  ICON TOOLTIPICON_WARNING_LARGE
				SetProperty( cFormName, cCtrlName, "ToolTip",;
					GetProperty (cFormName, cCtrlName, "CellEx", aKomorkaPodMysza [1],;
					GetProperty (cFormName, cCtrlName, "ColumnCount")))
			else
				SetProperty( cFormName, cCtrlName, "ToolTip","")
			endif
edk
Posts: 909
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: how to catch mouse event in a grid ?

Post by edk »

Yeap. http://hmgforum.com/hmgdoc/data/SetTool ... omDraw.htm
- If the Title is specified the ForeColor property does not work.
It should work in your code:

Code: Select all

if aKomorkaPodMysza [2] == GetProperty (cFormName, cCtrlName, "ColumnCount")-1	// uwagi
				SET TOOLTIPCUSTOMDRAW CONTROL G_Utargi OF OknoUtarg FORECOLOR {0,128,0}  ARRAYFONT aFontUwagi BALLOON .T. 	//TITLE "" //ICON TOOLTIPICON_WARNING_LARGE
				SetProperty( cFormName, cCtrlName, "ToolTip",;
					GetProperty (cFormName, cCtrlName, "CellEx", aKomorkaPodMysza [1],;
					GetProperty (cFormName, cCtrlName, "ColumnCount")-1))
			elseif aKomorkaPodMysza [2] == GetProperty (cFormName, cCtrlName, "ColumnCount") // pogoda				
				SET TOOLTIPCUSTOMDRAW CONTROL G_Utargi OF OknoUtarg FORECOLOR {255,0,0}  ARRAYFONT aFontPogoda BALLOON .T. 	//TITLE ""//POGODA" //  ICON TOOLTIPICON_WARNING_LARGE
				SetProperty( cFormName, cCtrlName, "ToolTip",;
					GetProperty (cFormName, cCtrlName, "CellEx", aKomorkaPodMysza [1],;
					GetProperty (cFormName, cCtrlName, "ColumnCount")))
			else
				SetProperty( cFormName, cCtrlName, "ToolTip","")
			endif
Sample:

Code: Select all

#include "hmg.ch"

Function Main
Local aRows [20] [3]

SET TOOLTIPCUSTOMDRAW ON

	DEFINE WINDOW Form_1 ;
		AT 0,0 ;
		WIDTH 800 ;
		HEIGHT 550 ;
		TITLE 'Hello World!' ;
		MAIN 

		aRows [1]	:= {'Simpson','Homer','555-5555'}
		aRows [2]	:= {'Mulder','Fox','324-6432'} 
		aRows [3]	:= {'Smart','Max','432-5892'} 
		aRows [4]	:= {'Grillo','Pepe','894-2332'} 
		aRows [5]	:= {'Kirk','James','346-9873'} 
		aRows [6]	:= {'Barriga','Carlos','394-9654'} 
		aRows [7]	:= {'Flanders','Ned','435-3211'} 
		aRows [8]	:= {'Smith','John','123-1234'} 
		aRows [9]	:= {'Pedemonti','Flavio','000-0000'} 
		aRows [10]	:= {'Gomez','Juan','583-4832'} 
		aRows [11]	:= {'Fernandez','Raul','321-4332'} 
		aRows [12]	:= {'Borges','Javier','326-9430'} 
		aRows [13]	:= {'Alvarez','Alberto','543-7898'} 
		aRows [14]	:= {'Gonzalez','Ambo','437-8473'} 
		aRows [15]	:= {'Batistuta','Gol','485-2843'} 
		aRows [16]	:= {'Vinazzi','Amigo','394-5983'} 
		aRows [17]	:= {'Pedemonti','Flavio','534-7984'} 
		aRows [18]	:= {'Samarbide','Armando','854-7873'} 
		aRows [19]	:= {'Pradon','Alejandra','???-????'} 
		aRows [20]	:= {'Reyes','Monica','432-5836'} 

		@ 10,10 GRID Grid_1 ;
			WIDTH 760 ;
			HEIGHT 240 ;
			HEADERS {'Last Name','First Name','Phone'} ;
			WIDTHS {140,140,140};
			ITEMS aRows ;
			VALUE {1,1} ;
			TOOLTIP 'Editable Grid Control' ;
			EDIT ;
	                JUSTIFY { GRID_JTFY_CENTER,GRID_JTFY_RIGHT, GRID_JTFY_RIGHT } ;
			CELLNAVIGATION 


		@ 250,10 GRID Grid_2 ;
			WIDTH 760 ;
			HEIGHT 240 ;
			HEADERS {'Last Name','First Name','Phone'} ;
			WIDTHS {140,140,140};
			ITEMS aRows ;
			VALUE 1 EDIT ;
			TOOLTIP 'Editable Grid Control' ;
			ON HEADCLICK { {||MsgInfo('Click 1')} , {||MsgInfo('Click 2')} , {||MsgInfo('Click 3')} } ;
                	JUSTIFY { GRID_JTFY_LEFT,GRID_JTFY_CENTER, GRID_JTFY_CENTER }
                	
   		CREATE EVENT PROCNAME Grid_ToolTip()
					
					
	END WINDOW

	CENTER WINDOW Form_1

	ACTIVATE WINDOW Form_1

Return

FUNCTION Grid_ToolTip()
LOCAL nHWnd := EventHWND(), aCellMouseOver, cCtrlName:="", cFormName:=""
LOCAL nIndex := GetControlIndexByHandle ( nHWnd )
LOCAL cCtrlType := IF( nIndex > 0, GetControlTypeByIndex (nIndex) , "")
LOCAL aFontList := { "Arial", "Juice ITC", "Webdings" }
LOCAL aFontWeather, aForeColor

STATIC aTT := {0,0}

IF cCtrlType == 'GRID'

	GetControlNameByHandle (nHWnd, @cCtrlName, @cFormName)

	aCellMouseOver := ListView_HitTest ( nHWnd , GetCursorRow() - GetWindowRow ( nHWnd )  , GetCursorCol() - GetWindowCol ( nHWnd ) )
	
	IF aTT [1] # aCellMouseOver [1] .OR. aTT [2] # aCellMouseOver [2]
		aTT [1] := aCellMouseOver [1]
		aTT [2] := aCellMouseOver [2]
		
		IF aCellMouseOver [1] = 0 .AND. aCellMouseOver [2] = 0
			SetProperty( cFormName, cCtrlName, "ToolTip", "")
		ELSE
		
			aFontWeather:= ARRAY FONT aFontList [ aCellMouseOver [2] ] SIZE aCellMouseOver [1] * 5
			aForeColor := { if (aCellMouseOver [2] = 1, 244, 0) , if (aCellMouseOver [2] = 2, 244, 0), if (aCellMouseOver [2] = 3, 244, 0) }
			SET TOOLTIPCUSTOMDRAW CONTROL &cCtrlName OF &cFormName FORECOLOR aForeColor ARRAYFONT aFontWeather BALLOON .T. 
		
			SetProperty( cFormName, cCtrlName, "ToolTip", "ToolTip for Row=" + Alltrim(HB_ValToStr( aCellMouseOver [1] )) + " Col=" + Alltrim(HB_ValToStr( aCellMouseOver [2] )) + " Value=" + GetProperty (cFormName, cCtrlName, "CellEx", aCellMouseOver [1], aCellMouseOver [2] ) )
		ENDIF
	ENDIF

ENDIF

RETURN Nil

Post Reply