GRID setfocus to a specific row, cell

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
User avatar
serge_girard
Posts: 1907
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Has thanked: 318 times
Been thanked: 74 times
Contact:

GRID setfocus to a specific row, cell

Post by serge_girard » 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...

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

User avatar
Rathinagiri
Posts: 5181
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 142 times
Been thanked: 131 times
Contact:

Post by Rathinagiri » Thu Oct 12, 2017 11:24 am

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: 1907
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Has thanked: 318 times
Been thanked: 74 times
Contact:

Post by serge_girard » Thu Oct 12, 2017 11:43 am

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

Serge

User avatar
mol
Posts: 2879
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Has thanked: 136 times
Been thanked: 76 times
Contact:

Post by mol » Thu Oct 12, 2017 5:49 pm

What is CHECKBOXENABLED grid? Where can I find sample?

User avatar
andyglezl
Posts: 859
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Has thanked: 7 times
Been thanked: 25 times
Contact:

Post by andyglezl » Fri Oct 13, 2017 3:08 am

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: 5181
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 142 times
Been thanked: 131 times
Contact:

Post by Rathinagiri » Fri Oct 13, 2017 4:59 am

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: 1907
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Has thanked: 318 times
Been thanked: 74 times
Contact:

Post by serge_girard » Fri Oct 13, 2017 6:54 am

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

User avatar
Rathinagiri
Posts: 5181
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 142 times
Been thanked: 131 times
Contact:

Post by Rathinagiri » Fri Oct 13, 2017 7:04 am

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: 1907
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Has thanked: 318 times
Been thanked: 74 times
Contact:

Post by serge_girard » Sat Oct 14, 2017 7:55 am

Thanks Rathi!

Serge

Post Reply