Page 1 of 3

grid dblclick

Posted: Mon Apr 26, 2021 7:05 pm
by franco
I am having trouble in grid with dblclick. My column 2 of grid is qty, which it must update a different table if changed so it must be locked.
I am trying to not allow double click on column 2.
I use on enter to make changes in the grid and in col 2 I must be able to lock the other file/record before allowing change. dblclick makes a mess in this case.
In the grid
on dblclick { if grid.value[2] = 2 no not allow double click ?

Thanks in advance..

Re: grid dblclick

Posted: Tue Apr 27, 2021 6:03 am
by mol
You should use WHEN codeblock table, which controls which column is editable

Re: grid dblclick

Posted: Tue Apr 27, 2021 9:58 am
by franco
Thanks Mol
I use WHEN but only with .T. or .F.
I see you can put code in the WHEN for a column, I did not know before.
Now I need to figure how to put code to see if I get a Lock then col 2 is .T. and after change it is .F.

Re: grid dblclick

Posted: Tue Apr 27, 2021 11:21 am
by mol
You can use something like this:

Code: Select all

function GridWhenTest
return This.CellColIndex == 2
Or, you can put any action required before cell edition.
After that, you can use VALID codeblocks determining if everything is good

Re: grid dblclick

Posted: Tue Apr 27, 2021 7:16 pm
by franco
how can I find lastcharacterpressed() I cannot find driving me nuts
if get last = chr(13)
return .T.
else
return .F.
endif

Re: grid dblclick

Posted: Tue Apr 27, 2021 8:06 pm
by Claudio Ricardo
Hi... In Cli**er and Harbour have LastKey () Example:
If LastKey () = 13
Return .T.
Else
Return .F.
EndIf
Another (This can be used in code block):
Function EnterKeyPress // or other name
Return Iif ( LastKey () = 13 , .T. , .F. )

Re: grid dblclick

Posted: Wed Apr 28, 2021 5:25 am
by mol
try to use piece of this code:

Code: Select all

	ch := HMG_GetLastCharacter(@hWnd)
	IF hWnd == GetControlHandle ("GridControlName","FormName")
		return if(asc(ch) == 13, .T., .F.)
	ENDIF

Re: grid dblclick

Posted: Wed Apr 28, 2021 8:21 am
by AUGE_OHR
hi,

if you "press" a Key than use HMG_GetLastVirtualKeyDown()

Code: Select all

LOCAL xKey   := HMG_GetLastVirtualKeyDown()
   DO CASE
      CASE xKey == VK_RETURN

Re: grid dblclick

Posted: Wed Apr 28, 2021 5:17 pm
by franco
Thanks guys for all your help. I came up with 2 ways to make it work from your suggestions.
I only want to use ENTER key to change column 2 in grid.
In grid definition.
1:

Code: Select all

COLUMNWHEN { {||.T.}, {|| iIf(HMG_GetLastVirtualKeyDown() == 13, .T., .F.)}, {||.T.}, {||.T.}, {||.T.}, {||.T.}}
2:

Code: Select all

COLUMNWHEN { {||.T.}, {|| CHECK()}, {||.T.}, {||.T.}, {||.T.}, {||.T.}}
FUNCTION CHECK
	Local aCell, ch   := HMG_GetLastVirtualKeyDown()
	HMG_CleanLastVirtualKeyDown()
	aCell := form_1.Grid_1.value
	If ch == 13 .and. aCell[2] = 2 
	 	aCell[2] := 3
		form_1.Grid_1.value := aCell
		Return .T.
	Else
		form_1.Grid_1.value := aCell
		Return .F.
	Endif
RETURN

Re: grid dblclick

Posted: Sun May 02, 2021 6:52 pm
by franco
I am trying to find something that must be simple. I need not the value of grid but what the cell value is before save.
When linked to a table the before the save the cell value can be different from table. I AM HAVING TROUBLE FINDING THAT VALUE.
Also on change procedure always fires at least twice because when you enter cell it has change then you modify cell it has change.
I have created a public variable that in the change procedure I make the first change return to grid then process the second change.