Page 1 of 1

GRID setfocus to a specific row, cell

Posted: Thu Oct 12, 2017 10:57 am
by serge_girard
Hello,

I have a small program which allows me to add/delete a row in a grid.

When I add an ITEM I want the focus to be set a the second cell from the last insert row + set to be in EDIT, in order to fill in the new value.
What happens now is that a row is inserted but one has to double click to get insert the new value.

So I need two things:
1 setfocus to the inserted row at column 2
2 force to EDIT mode.

This is the code I use. If someone would be so kind to help...

Code: Select all

#include "hmg.ch"
 

FUNCTION MAIN()
/*************/
aENUM2   := {}
FOR A = 1 TO 10
   AADD(aENUM2, {.F., ALLTRIM(STR(A))}  ) // some data
NEXT


DEFINE WINDOW Form_1   ;
   AT 0,0	           ;
   WIDTH  290	;  
   HEIGHT 720 ;
   TITLE ' Values '   ;	
   ICON  "DEFAULT"	;
   MAIN

   ON KEY ESCAPE ACTION { Form_1.Release }


   DEFINE GRID Grid_1	
      ROW 10
      COL 10
      WIDTH  270
      HEIGHT 600
      HEADERS {'DEL', 'Values'}
      WIDTHS  {40,     210}
      JUSTIFY {GRID_JTFY_LEFT, GRID_JTFY_LEFT}  
      COLUMNWHEN     {  {|| .T. },  { || .T. }  }
      COLUMNCONTROLS {   { 'CHECKBOX', 'Yes' , 'No' }, ;
                         { 'TEXTBOX',  'CHARACTER'}}
      ALLOWEDIT      .T.
      ITEMS aENUM2
   END GRID         


   DEFINE BUTTON Start_ADD
      ROW    620
      COL    10 
      WIDTH  50
      HEIGHT 70
      ACTION NEW_VALUES()
      CAPTION "Add"
      TRANSPARENT .T.
      TOOLTIP "Add a line"
      PICTURE "HMG_EDIT_NEW"
      PICTALIGNMENT TOP
   END BUTTON

  
END WINDOW

ACTIVATE WINDOW Form_1

RETURN



FUNCTION NEW_VALUES()
/***************************/
Form_1.Grid_1.AddItem({.F.,''})
nLAST := Form_1.Grid_1.Itemcount 
//cCell := Form_1.Grid_1.CellEx( nLAST, 2 )
DoMethod( 'Form_1' , 'Grid_1' , 'SetFocus', Form_1.Grid_1.CellEx( nLAST, 2 ) ) // this doen't work
RETURN
Thanks, Serge

Re: GRID setfocus to a specific row, cell

Posted: Thu Oct 12, 2017 11:24 am
by Rathinagiri
Even though I can't help you in this regard, why can't you use 'CHECKBOXENABLED' grid? It is very useful for your purpose here.

Re: GRID setfocus to a specific row, cell

Posted: Thu Oct 12, 2017 11:43 am
by serge_girard
Thanks Rathi, very good idea ! I was forgotten this option...
Hope that someone can help with other question.

Serge

Re: GRID setfocus to a specific row, cell

Posted: Thu Oct 12, 2017 5:49 pm
by mol
What is CHECKBOXENABLED grid? Where can I find sample?

Re: GRID setfocus to a specific row, cell

Posted: Fri Oct 13, 2017 3:08 am
by andyglezl
serge_girard wrote: Thu Oct 12, 2017 10:57 am Hello,

I have a small program which allows me to add/delete a row in a grid.

When I add an ITEM I want the focus to be set a the second cell from the last insert row + set to be in EDIT, in order to fill in the new value.
What happens now is that a row is inserted but one has to double click to get insert the new value.

So I need two things:
1 setfocus to the inserted row at column 2
2 force to EDIT mode.

This is the code I use. If someone would be so kind to help...


Hi, Serge
maybe this can help...

Code: Select all

#include "hmg.ch"
 

FUNCTION MAIN()
/*************/
aENUM2   := {}
FOR A = 1 TO 10
   AADD(aENUM2, {.F., ALLTRIM(STR(A))}  ) // some data
NEXT


DEFINE WINDOW Form_1   ;
   AT 0,0	           ;
   WIDTH  290	;  
   HEIGHT 720 ;
   TITLE ' Values '   ;	
   ICON  "DEFAULT"	;
   MAIN

   ON KEY ESCAPE ACTION { Form_1.Release }


   DEFINE GRID Grid_1	
      ROW 10
      COL 10
      WIDTH  270
      HEIGHT 600
      HEADERS {'DEL', 'Values'}
      WIDTHS  {40,     210}
	  VALUE { 1, 1 }	 // ADD THIS
      JUSTIFY {GRID_JTFY_LEFT, GRID_JTFY_LEFT}  
      COLUMNWHEN     {  {|| .T. },  { || .T. }  }
      COLUMNCONTROLS {   { 'CHECKBOX', 'Yes' , 'No' }, ;
                         { 'TEXTBOX',  'CHARACTER'}}
      CELLNAVIGATION .T. // ADD THIS
      ALLOWEDIT      .T.
      ITEMS aENUM2
   END GRID         


   DEFINE BUTTON Start_ADD
      ROW    620
      COL    10 
      WIDTH  50
      HEIGHT 70
      ACTION NEW_VALUES()
      CAPTION "Add"
      TRANSPARENT .T.
      TABSTOP .F.
      TOOLTIP "Add a line"
      PICTURE "HMG_EDIT_NEW"
      PICTALIGNMENT TOP
   END BUTTON

  
END WINDOW

ACTIVATE WINDOW Form_1

RETURN



FUNCTION NEW_VALUES()
/***************************/
Form_1.Grid_1.AddItem({.F.,Form_1.Grid_1.Itemcount+1})
Form_1.Grid_1.SetFocus
Form_1.Grid_1.Value := { Form_1.Grid_1.Itemcount, 2 }
_PushKey( VK_RIGHT )
_PushKey( VK_RETURN )
RETURN

Re: GRID setfocus to a specific row, cell

Posted: Fri Oct 13, 2017 4:59 am
by Rathinagiri
Very nice!

Or, you can do like this also:

Code: Select all

_PushKey( VK_RETURN )
_PushKey( VK_RETURN )

Re: GRID setfocus to a specific row, cell

Posted: Fri Oct 13, 2017 6:54 am
by serge_girard
Thanks Andrés and Rathi !

Perfectly working and exactly what I want. Really great!

BTW: What is :

Code: Select all

VALUE { 1, 1 }	 // ADD THIS 
for?

Serge

Re: GRID setfocus to a specific row, cell

Posted: Fri Oct 13, 2017 7:04 am
by Rathinagiri
That is to make the default value for the grid.

Re: GRID setfocus to a specific row, cell

Posted: Sat Oct 14, 2017 7:55 am
by serge_girard
Thanks Rathi!

Serge