GRID setfocus to a specific row, cell

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
User avatar
serge_girard
Posts: 3161
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

GRID setfocus to a specific row, cell

Post 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
There's nothing you can do that can't be done...
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: GRID setfocus to a specific row, cell

Post 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.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
serge_girard
Posts: 3161
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: GRID setfocus to a specific row, cell

Post by serge_girard »

Thanks Rathi, very good idea ! I was forgotten this option...
Hope that someone can help with other question.

Serge
There's nothing you can do that can't be done...
User avatar
mol
Posts: 3718
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: GRID setfocus to a specific row, cell

Post by mol »

What is CHECKBOXENABLED grid? Where can I find sample?
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: GRID setfocus to a specific row, cell

Post 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
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: GRID setfocus to a specific row, cell

Post by Rathinagiri »

Very nice!

Or, you can do like this also:

Code: Select all

_PushKey( VK_RETURN )
_PushKey( VK_RETURN )
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
serge_girard
Posts: 3161
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: GRID setfocus to a specific row, cell

Post 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
There's nothing you can do that can't be done...
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: GRID setfocus to a specific row, cell

Post by Rathinagiri »

That is to make the default value for the grid.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
serge_girard
Posts: 3161
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: GRID setfocus to a specific row, cell

Post by serge_girard »

Thanks Rathi!

Serge
There's nothing you can do that can't be done...
Post Reply