Enter key in a grid
Moderator: Rathinagiri
Enter key in a grid
Hi friends,
I have created a grid, the data (names) are stored in an array with just one column. Navigating up and down the rows can be simply done. To find out the CellRowIndex I use nRow:=This.CellRowIndex. Works fine with OnDblClick.
If I use the Enter key I always get a CellRowIndex of 0 (zero) and of course an array access error .In clipper the first index of an array seems to be 1 and not 0 like in "C". Set navigation extended is on. In grid control onenter does not work. Is there any workaround for this?
Maybe I can try with Listbox.
TIA
Robert
I have created a grid, the data (names) are stored in an array with just one column. Navigating up and down the rows can be simply done. To find out the CellRowIndex I use nRow:=This.CellRowIndex. Works fine with OnDblClick.
If I use the Enter key I always get a CellRowIndex of 0 (zero) and of course an array access error .In clipper the first index of an array seems to be 1 and not 0 like in "C". Set navigation extended is on. In grid control onenter does not work. Is there any workaround for this?
Maybe I can try with Listbox.
TIA
Robert
- AUGE_OHR
- Posts: 2117
- Joined: Sun Aug 25, 2019 3:12 pm
- DBs Used: DBF, PostgreSQL, MySQL, SQLite
- Location: Hamburg, Germany
Re: Enter key in a grid
hi,
GRID have "itself"
---
about DblClick
GRID have "itself"
Code: Select all
ONKEYabout DblClick
The following data are available at ‘OnDblClick’ procedure:
This ...
Note: These properties are not available when OnDblClick procedure is fired by <Enter> key pressing.
have fun
Jimmy
Jimmy
Re: Enter key in a grid
Hi Jimmy, thanks for your hint, had not found onkey-event.
Robert
Robert
Re: Enter key in a grid
Maybe this can help you:
Nex.
Code: Select all
ON KEY RETURN OF Form_1 ACTION (...)- Claudio Ricardo
- Posts: 367
- Joined: Tue Oct 27, 2020 3:38 am
- DBs Used: DBF, MySQL, MariaDB
- Location: Bs. As. - Argentina
Re: Enter key in a grid
Hi... i use:
aArray is unidimentional and contain all row selected values...
Work with doubleclick or enter over highlight row.
Code: Select all
LOCAL nPos := GetProperty ("Form_Name" , "Grid_Name" , "Value")
LOCAL aArray := GetProperty ("Form_Name" , "Grid_Name" , "Item" , nPos)
LOCAL xCol_1, xCol_2
xCol_1 := aArray [1]
xCol_2 := aArray [2] // etc....
Work with doubleclick or enter over highlight row.
Corrige al sabio y lo harás más sabio, Corrige al necio y lo harás tu enemigo.
WhatsApp / Telegram: +54 911-63016162
WhatsApp / Telegram: +54 911-63016162
- AUGE_OHR
- Posts: 2117
- Joined: Sun Aug 25, 2019 3:12 pm
- DBs Used: DBF, PostgreSQL, MySQL, SQLite
- Location: Hamburg, Germany
Re: Enter key in a grid
hi,
forgot to say that it work with "virtual-Key"
also have a look at
X:\hmg.3.4.4\SAMPLES\Controls\Grid\GridIncrementalSearch
forgot to say that it work with "virtual-Key"
Code: Select all
GRID ...
ON KEY DoGridKey1( cForm, cObj )Code: Select all
PROCEDURE DoGridKey1( cForm, cObj )
LOCAL xKey := HMG_GetLastVirtualKeyDown()
DO CASE
CASE xKey == VK_F1 .AND. .NOT. IsKeyVK()
HelpFile()
CASE xKey == VK_T .AND. HMG_VirtualKeyIsPressed( VK_CONTROL )
NewTab()
CASE xKey == VK_U .AND. HMG_VirtualKeyIsPressed( VK_CONTROL )
ChangeLeftRight()
...
CASE xKey == VK_RETURN
// it IS include as DblClick
// DoDblClick()
X:\hmg.3.4.4\SAMPLES\Controls\Grid\GridIncrementalSearch
have fun
Jimmy
Jimmy
Re: Enter key in a grid
Hi Robert.ROBROS wrote: ↑Tue Nov 16, 2021 7:39 pm Hi friends,
I have created a grid, the data (names) are stored in an array with just one column. Navigating up and down the rows can be simply done. To find out the CellRowIndex I use nRow:=This.CellRowIndex. Works fine with OnDblClick.
If I use the Enter key I always get a CellRowIndex of 0 (zero) and of course an array access error .In clipper the first index of an array seems to be 1 and not 0 like in "C". Set navigation extended is on. In grid control onenter does not work. Is there any workaround for this?
Maybe I can try with Listbox.
TIA
Robert
Try to use
Code: Select all
nRow := This.CellRowFocusedCode: Select all
nRow := This.CellRowIndexCode: Select all
#include "hmg.ch"
Function Main
Local i, j, xSel
Local aMultiArray:={1 , 2 , 'string' , Nil , { 5, 55, 555 }, .T. , { 7 , { '7a' , '7b' , { '7c' , { 77.77 , 777.777 } } } , 777 } , 8 }
Local aSingleArray:={1,2,3,4,5,6,7,8,9}
Local xNOTArray:= 1
Local aEmptyArray:={}
Local aTwoDimArray:=Array(10,10)
FOR i = 1 TO LEN( aTwoDimArray )
FOR j = 1 TO LEN( aTwoDimArray [i] )
aTwoDimArray [i][j] := ((i - 1) * 10) + j - 1
NEXT j
NEXT i
DEFINE WINDOW Form_1 ;
AT 0,0 ;
WIDTH 450 ;
HEIGHT 400 ;
TITLE 'Hello' ;
MAIN
DEFINE MAIN MENU
DEFINE POPUP 'Matrix Browse'
MENUITEM 'Single' ACTION ( xSel := MatrixBrowse( aSingleArray ), MsgBox ('Selected value ' + hb_valToStr( xSel )) )
MENUITEM 'Two-dimensional array' ACTION ( xSel := MatrixBrowse( aTwoDimArray ), MsgBox ('Selected value ' + hb_valToStr( xSel )) )
MENUITEM 'Multi-dimensional array' ACTION ( xSel := MatrixBrowse( aMultiArray ), MsgBox ('Selected value ' + hb_valToStr( xSel )) )
MENUITEM 'Empty array' ACTION ( xSel := MatrixBrowse( aEmptyArray ), MsgBox ('Selected value ' + hb_valToStr( xSel )) )
MENUITEM 'Not an Array' ACTION ( xSel := MatrixBrowse( xNOTArray ), MsgBox ('Selected value ' + hb_valToStr( xSel )) )
END POPUP
END MENU
END WINDOW
CENTER WINDOW Form_1
ACTIVATE WINDOW Form_1
Return
*******************************************************************************
Function MatrixBrowse ( aAnyArray )
Local nItems, aColumns, cFormName
Local nFormNo := 1
Public _xMatrixValue
IF .NOT. HB_isArray( aAnyArray )
MsgStop ("The variable is not an array.")
RETURN
ENDIF
nItems := 1
FOR EACH _xMatrixValue IN aAnyArray
IF hb_isArray( _xMatrixValue )
nItems := MAX ( nItems, LEN( _xMatrixValue ) )
ENDIF
NEXT
_xMatrixValue := Nil
aColumns := Array ( nItems )
AEval( aColumns, { | x, y | aColumns [ y ] := "Column " + Alltrim(Str( y )) })
DO WHILE .T.
cFormName := "_MatrixForm_" + Alltrim( Str ( nFormNo ) )
IF !_IsWindowDefined ( cFormName )
EXIT
ENDIF
nFormNo ++
ENDDO
DEFINE WINDOW &cFormName ;
AT 0,0 ;
WIDTH nItems * 100 + 50 ;
HEIGHT MIN ( LEN( aAnyArray ) * 25 + 100, GetDesktopHeight() ) ;
TITLE 'Matrix browse #' + Alltrim( Str ( nFormNo ) ) ;
MODAL
@ 5,5 GRID Grid_1 ;
WIDTH nItems * 100 + 20 ;
HEIGHT MIN ( LEN( aAnyArray ) * 25 + 20, GetDesktopHeight() - 80) ;
HEADERS aColumns ;
WIDTHS AFill ( Array (nItems), 100 );
DYNAMICFORECOLOR AFill ( Array (nItems), { || if ( hb_isString(This.CellValue) .AND. This.CellValue = "{ SubArray }" , RED, BLACK ) } ) ;
VIRTUAL ;
ITEMCOUNT LEN( aAnyArray ) ;
ON QUERYDATA QueryArray ( aAnyArray ) ;
CELLNAVIGATION ;
VALUE { 1, 1 } ;
ON DBLCLICK OnKeyMatrixBrowse( aAnyArray, cFormName ) ;
ON KEY OnKeyMatrixBrowse( aAnyArray, cFormName )
END WINDOW
CENTER WINDOW &cFormName
ACTIVATE WINDOW &cFormName
Return _xMatrixValue
*******************************************
Function OnKeyMatrixBrowse ( aArray, cFormName )
Local nRow := GetProperty(cFormName, 'Grid_1', 'CellRowFocused' )
Local nCol := GetProperty(cFormName, 'Grid_1', 'CellColFocused' )
Local lEnter := HMG_GetLastVirtualKeyDown() == VK_RETURN .OR. HMG_GetLastMouseMessage() == WM_LBUTTONDBLCLK
HMG_CleanLastVirtualKeyDown()
HMG_CleanLastMouseMessage()
IF lEnter
IF GetProperty( cFormName, 'Grid_1', 'CellEx', nRow, nCol ) == '{ SubArray }'
//show sub-Array
MatrixBrowse( aArray [nRow] [nCol] )
ELSE
//Quit
IF LEN( aArray ) > 0
IF hb_isArray( aArray [nRow] )
_xMatrixValue := aArray [nRow] [nCol]
ELSEIF nCol == 1
_xMatrixValue := aArray [nRow]
ENDIF
ELSE
_xMatrixValue := Nil
ENDIF
DoMethod (cFormName, 'Release')
ENDIF
ENDIF
Return NIL
******************************************
Procedure QueryArray( aArray )
IF !hb_isArray ( aArray [This.QueryRowIndex] )
IF This.QueryColIndex == 1
This.QueryData := hb_ValToStr( aArray [This.QueryRowIndex] )
ELSE
This.QueryData := ""
ENDIF
ELSEIF hb_isArray ( aArray [This.QueryRowIndex] [This.QueryColIndex] )
This.QueryData := "{ SubArray }"
ELSE
This.QueryData := hb_ValToStr( aArray [This.QueryRowIndex] [This.QueryColIndex] )
ENDIF
Return
Re: Enter key in a grid
Thanks for all your suggestions.
I will try.
Robert
I will try.
Robert