HeadClick in browse help

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

franco
Posts: 877
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

HeadClick in browse help

Post by franco »

I need help on this in browse.
When I go to an index function from headclick I can not set focus to a button or text box out of the browse in the program I must mouse click on return.
If I use a button outside the browse in current window when I return it can set focus where I want, but not from head click.
Anybody got any thoughts ?
All The Best,
Franco
Canada
User avatar
Claudio Ricardo
Posts: 367
Joined: Tue Oct 27, 2020 3:38 am
DBs Used: DBF, MySQL, MariaDB
Location: Bs. As. - Argentina

Re: HeadClick in browse help

Post by Claudio Ricardo »

Hi... I use:
Function OnHeadClick
Index On xField To xIndexFile
DoMethod ("Form_X" , "Browse_X" , "Refresh")
DoMethod ("Form_X" , "Control_X" , "SetFocus") // control you need focus
Return Nil

It works for me putting the browse control last in control order.
Best regards.
Corrige al sabio y lo harás más sabio, Corrige al necio y lo harás tu enemigo.
WhatsApp / Telegram: +54 911-63016162
franco
Posts: 877
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: HeadClick in browse help

Post by franco »

Claudio,
This still does not work. It will work from a button but not from Onheadclick. It must be something to do with return to header
This my define, and table = INV T1 is parameter = table
*****************
DEFINE BROWSE brwItems5
ROW 26
COL 0
WIDTH W1 + W2+W3+W4+W5+25 // 400
HEIGHT HI1 -20 //290
FONTCOLOR { 0, 0, 0 }
BACKCOLOR { 180, 180, 210} // white BACKCOLOR {255,255,255 }
HEADERS {HD1 , HD2, HD3, HD4, HD5}
WIDTHS {W1, W2, W3, W4, W5}
WORKAREA &T1 //inv
FIELDS {&WID1}
ONGOTFOCUS { || frmbrwcrs5.Button_1.Caption := '{F2) &New Search' }
ONDBLCLICK { || dbgoto(this.value), goo55() } // frmbrwcrs5.release }
IF T1 = 'INV'
ONHEADCLICK { {|| BRTEMP(fc11)}, {|| BRTEMP(fc21)}, {||BRTEMP(' ') }, {|| BRTEMP( ' ') }, {|| BRTEMP(' ') }} // Can only send character fields at this time.
ENDIF
IF T1 = 'NAME'
ONHEADCLICK { {|| BRTEMP(fc11)}, {|| BRTEMP(fc21) }, {|| BRTEMP(fc31) }, {|| BRTEMP(' ') }, {|| BRTEMP(' ') }}
ENDIF
ONCHANGE { || { dbgoto(this.value), this.save, this.refresh } , {if (deleted(), frmbrwcrs5.label_3.visible := .T., frmbrwcrs5.label_3.visible := .F.)},{this.refresh}} //, RE := THIS.VALUE } //dbgoto(this.value),
END BROWSE

Function BRTEMP
parameter brtemp

if len(alltrim(brtemp)) > 0
if msgyesno('Do You Wish to Index on '+brtemp) //msgbox(brtemp)
WAIT WINDOW 'Indexing 1,000,000 Records ** Please Wait' NOWAIT
index on UPPER(&brtemp) to C:\BRWCRS5\TPBR5.NTX
go top
frmbrwcrs5.textSEARCH5.value := ' '
*frmbrwcrs5.textSEARCH5.SETFOCUS
frmbrwcrs5.label_4.value := 'Sorted By '+brtemp
DoMethod ("Frmbrwcrs5", "BrwItems5","Refresh")
DoMethod ("Frmbrwcrs5", "TextSEARCH5", "SetFocus")

WAIT CLEAR
endif

endif
return Nil
Franco
All The Best,
Franco
Canada
movilceles
Posts: 20
Joined: Sun Dec 04, 2016 1:43 pm
DBs Used: DBF
Location: Murcia - España

Re: HeadClick in browse help

Post by movilceles »

Hello Franco, try to put it like this:
.....
......
WAIT CLEAR
endif

endif

DoMethod ("Frmbrwcrs5", "BrwItems5","Refresh")
DoMethod ("Frmbrwcrs5", "TextSEARCH5", "SetFocus")

return Nil
Celes
Saludos / Regards :P - :idea: Cuanto mas simple mejor !! / The simpler the better !!
franco
Posts: 877
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: HeadClick in browse help

Post by franco »

Still does not work. I think I know what`s wrong. It returns to the browse, so setfocus does not work before.
I have in the window of the browse ON KEY F2 OF frmbrwcrs5 ACTION frmbrwcrs5.textSEARCH5.SETFOCUS
I need but can not get to work, when I am in the grid I have SET KEY F2 to do what I want. So when return to grid must keyboard F2, also
TAB TAB will work manually. I need V
ONHEADCLICK { {|| BRTEMP(fc11)}, {|| BRTEMP(fc21), keyboard FUNCTION 2}, {||BRTEMP(' ') }, {|| BRTEMP( ' ') }, {|| BRTEMP(' ') }}
or ONHEADCLICK { {|| BRTEMP(fc11)}, {|| BRTEMP(fc21), _Pushkey(chr(9)+chr(9)}, {||BRTEMP(' ') }, {|| BRTEMP( ' ') }, {|| BRTEMP(' ') }}

I am having trouble getting these to work
All The Best,
Franco
Canada
franco
Posts: 877
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: HeadClick in browse help

Post by franco »

I have it figured out.
After I get back to browse from index function.
ONHEADCLICK { {|| BRTEMP(fc11), _pushkey(9), pushkey(9)}} etc: after each index click.
WOW what a 3 day chore.
I will fix my brs5 program and renter it in the forum here and other post.
Thanks to all
Franco
All The Best,
Franco
Canada
User avatar
mol
Posts: 3774
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: HeadClick in browse help

Post by mol »

I think I found better solution:
before BROWSE definition put declaration:

Code: Select all

  private cControlToSetFocus := "TextSEARCH5"
in OnHeadClick code add

Code: Select all

  cControlToSetFocus := "TextSEARCH5"
in BROWSE definition OnGotFocus method put some code:

Code: Select all

  if !empty(cControlToSetFocus)
     DoMethod ("Frmbrwcrs5", "TextSEARCH5", "SetFocus")
     //clear this variable to allow BROWSE to get focus 
     cControlToSetFocus := ""
  endif
It works excellent for me
franco
Posts: 877
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: HeadClick in browse help

Post by franco »

Hi Mol,
I can not get it to work. I think the browse has not left focus on the index, so on return it already has focus so it is not getting new focus.
I can not get domethod to work even without any if`s or other is`s. Is there a #define for domethod or is it in hmg`s define.
I would rather _pushkey(Function 2) but I can not find the variable for F2.
Do you know how to _pushkey(F2)
Franco
All The Best,
Franco
Canada
User avatar
mol
Posts: 3774
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: HeadClick in browse help

Post by mol »

Here is my working sampe. When T_Search is focused and you click on browse header, T_Search keeps focus.

Code: Select all

#include "hmg.ch"

Function Main

	Local aRows [20] [3]
	local i
	local aDBF := {	{"LastName", "C", 20, 0},;
					{"FirstName", "C", 20, 0},;
					{"Phone", "C", 20, 0} }
	
	private cSearchControl := ""
	
	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'} 
	
	
	// prepare database
	
	DbCreate("test", aDBF)
	use test new
	index on lastname to test1
	index on firstname to test2
	index on phone to test3
	close indexes
	set index  to test1,test2,test3
	for i:=1 to len(aRows)
		append blank
		replace;
			LastName	with aRows[i,1],;
			FirstName	with aRows[i,2],;
			Phone	with aRows[i,3]
	next i
	

	DEFINE WINDOW Form_1 ;
		AT 0,0 ;
		WIDTH 800 ;
		HEIGHT 550 ;
		TITLE 'OnHeadClick Test' ;
		MAIN 


		DEFINE BROWSE BR1
			ROW 10
			COL 10
			WIDTH 760
			HEIGHT 400
			HEADERS {'Last Name','First Name','Phone'}
			FIELDS  {'LastName','FirstName','Phone'}
			WIDTHS {140,140,140}
			WORKAREA test
			ONHEADCLICK {{|| BR1_OnHeadClick(1)},;
							{|| BR1_OnHeadClick(2)},;
							{|| BR1_OnHeadClick(3)} }
			ONGOTFOCUS BR1_OnGotFocus()
		END BROWSE
		
		DEFINE TEXTBOX T_Search
			ROW 430
			COL 10
			ONENTER BR1_Search()
		END TEXTBOX
		
	END WINDOW

	CENTER WINDOW Form_1

	ACTIVATE WINDOW Form_1

Return
*------------------
function BR1_OnHeadClick
	param nOrder
	
	cSearchControl := "T_Search"
	
	test->(DBSetOrder(nOrder))
	Form_1.BR1.Refresh
return
*-----------------
function BR1_OnGotFocus
	if !empty(cSearchControl)
		DoMethod("Form_1",cSearchControl, "SetFocus")
		cSearchControl := ""
	endif
return
*-----------------
function BR1_Search

	test->(DBSeek(This.Value))
	Form_1.BR1.Value := test->(RecNo())
	//Form_1.BR1.Refresh
return
franco
Posts: 877
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: HeadClick in browse help

Post by franco »

Mol, The way mine set up the when the browse has focus the record is blue. When not focus it is light grey.
When it is blue even your program does not focus the textbox. I need the Blue focus to use the ONENTER(Answer Browse program) or ESCAPE(Cancel)
from calling program. The _PushKey work good in my program. I am going to post a new one. Just waiting for a response from my other post.
Your program works fine but is just a bit different. I don`t think the browse has real focus as it is not blue, but is following the table.
Franco
All The Best,
Franco
Canada
Post Reply