Button position in a grid

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

ROBROS
Posts: 88
Joined: Thu May 25, 2017 6:30 pm
DBs Used: DBF
Has thanked: 36 times
Been thanked: 7 times

Button position in a grid

Post by ROBROS » Sun Dec 10, 2017 12:20 pm

Hi friends,
for my still growing app I must enter some data, which only exist on a sheet of paper.

in table bbpers.dbf are information of about 40 truckers, who do their job, delievering our customers with food-products.
For calculations I need daily for some of them (3 or 5) one special information out of 3 possible informations, I intend to do this with radiogroup control.
My problem is:
I have defined a grid and can select daily the persons of which I need an information. Works just fine, but:

I have defined a button, that, when clicked closes the grid.

As soon as I need a second "page" in the grid the button changes position on the screen, disappear, shows up again.

See my code.

Code: Select all

#include <hmg.ch>

//prg  is called from a main.prg

SET LANGUAGE TO GERMAN
REQUEST HB_SETCODEPAGE
HB_SETCODEPAGE ('ES850')


public cPersnr
 
   OpenTables()
		 

   DEFINE WINDOW Form_1 ;
      AT 10,10          ;
      WIDTH 900         ;
      HEIGHT 1200        ;
      TITLE "Fahrer	"  ;
	    
 
      @ 10,10 GRID Grid_1                        ;
      PARENT Form_1                           ;
      WIDTH 1000                               ;
      HEIGHT 830                              ;
      value {1,1}         ;
	  On DblClick test()   ;
  	  HEADERS {"Persnr","Name","Vorname","Strasse","PLZ","Ort"}      ;
      WIDTHS {50,100,100,100,50,100}                    ;
      ROWSOURCE "bbpers"  ;
	  COLUMNFIELDS {"bbpers->persnr","bbpers->name","bbpers->vname","bbpers->str","bbpers->plz","bbpers->ort"} 
      On Key F10 ACTION ende()  
	  
	  
     @ 40, 600 BUTTON button       ;
      PARENT form_1            ;
      CAPTION "Ende F-10"   ;
      WIDTH 200                 ;
      HEIGHT 50                 ;
	  ONCLICK form_1.release
	  

   END WINDOW
      
   ACTIVATE WINDOW Form_1
   
   RETURN NIL
   
  



   procedure OpenTables()
   USE bbpers
   
   index on name+vname to nvname
   return nil
   
   function test
   SetProperty('Form_1', 'Grid_1','Visible', .F.)
   go Form_1.Grid_1.RecNo
   MsgInfo (bbpers->persnr+bbpers->name+str(Form_1.Grid_1.RecNo))
   SetProperty('Form_1', 'Grid_1','Visible', .T.)
   Form_1.Grid_1.SetFocus
   return
   
   function ende
   form_1.release
   hb_setcodepage('DEWIN')
   
   return
I assume the solution is onchange event combined with refresh method, but I didn't succeed.

I hope someone can help.
Thx in advance.

Greetings
Robert

User avatar
serge_girard
Posts: 2030
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Has thanked: 378 times
Been thanked: 87 times
Contact:

Post by serge_girard » Sun Dec 10, 2017 2:13 pm

Robert,

As I see now the button is located inside the grid (@10,10 width 1000 height 830). This will cause strange effects!

Serge

ROBROS
Posts: 88
Joined: Thu May 25, 2017 6:30 pm
DBs Used: DBF
Has thanked: 36 times
Been thanked: 7 times

Post by ROBROS » Sun Dec 10, 2017 2:29 pm

Hi Serge, great to hear from you.

tabx.prg is called from a main menu within a main window win_1. I will define the button outside the grid.

Thank you.

Robert

User avatar
serge_girard
Posts: 2030
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Has thanked: 378 times
Been thanked: 87 times
Contact:

Post by serge_girard » Sun Dec 10, 2017 2:36 pm

OK, I made it as a Main.prg, created your DBF and noticed that the button was not visible because it was 'under' the grid. So closing the grid made it temporarily visible.

Serge

ROBROS
Posts: 88
Joined: Thu May 25, 2017 6:30 pm
DBs Used: DBF
Has thanked: 36 times
Been thanked: 7 times

Post by ROBROS » Sun Dec 10, 2017 5:15 pm

I wrote:
I have defined a button, that, when clicked closes the grid.
That's what the button should do, now I've found, that actually it does nothing but make the button disappear.

On key F10 does the job.

I have tried to define the button outside the grid control after END WINDOW.
No success

Robert

User avatar
serge_girard
Posts: 2030
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Has thanked: 378 times
Been thanked: 87 times
Contact:

Post by serge_girard » Sun Dec 10, 2017 5:46 pm

Robert,

The BUTTON release the form and so does function ende() ( + hb_setcodepage('DEWIN') )

I am afraid I don't understand what you want to achieve when double-clicking and what you want to let happen when F10 is pressed.

Code: Select all

DEFINE WINDOW Form_1 ;
   AT 10,10          ;
   WIDTH 900         ;
   HEIGHT 1200        ;
   TITLE "Fahrer	"  ;
   MAIN 

   On Key F10 ACTION ende()  

   @ 10,10 GRID Grid_1 ;
   PARENT Form_1                           ;
   WIDTH 400                               ;
   HEIGHT 400                              ;
   value {1,1}         ;
   On DblClick test()   ;
   HEADERS {"Persnr","Name","Vorname","Strasse","PLZ","Ort"}      ;
   WIDTHS {50,100,100,100,50,100}                    ;
   ROWSOURCE "bbpers"  ;
   COLUMNFIELDS {"bbpers->persnr","bbpers->name","bbpers->vORname","bbpers->strASSE","bbpers->plz","bbpers->ort"} 
  
  
   @ 40, 600 BUTTON button       ;
   PARENT form_1            ;
   CAPTION "Ende F-10"   ;
   WIDTH 200                 ;
   HEIGHT 50                 ;
   ONCLICK form_1.release
  

END WINDOW
In this case the button is OK .

Please explain further!

Serge

ROBROS
Posts: 88
Joined: Thu May 25, 2017 6:30 pm
DBs Used: DBF
Has thanked: 36 times
Been thanked: 7 times

Post by ROBROS » Sun Dec 10, 2017 6:28 pm

Ok Serge,

I'll try to explain it in my poor english:

the test function should only show me if I have selected the correct record from the grid, it will be replaced by a function with input dialog, this input will be appended to a new table.

This table has three fields:

persnr,C,4 (comes from the grid)

date ,D,8 (default = date()) but must be changeable in rare situations, how to handle this you have taught me some months ago, and this is done in my main.prg.

kz,C,1 for any persnr and date only one value out of three is possible.

When this input is done, I want to return to the grid and do the next selection for the input function.

When no further persnr (mostly max. 5/day) has to be selected and appended to that table and I have returned to the grid, I want to close the grid.

Onkey F10 and onclick provide that action can be done by keyboard as well as by mouseclick

Thank you for your effort :)

Robert

User avatar
serge_girard
Posts: 2030
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Has thanked: 378 times
Been thanked: 87 times
Contact:

Post by serge_girard » Mon Dec 11, 2017 8:11 am

Robert,

Maybe this is you mean:

Code: Select all

#include "hmg.ch"
 

//prg  is called from a main.prg

SET LANGUAGE TO GERMAN
REQUEST HB_SETCODEPAGE
HB_SETCODEPAGE ('ES850')


public cPersnr
 
IF .NOT. FILE('newtable.dbf')  
   aSTRUCT  := {}
   AADD( aSTRUCT , { 'persnr'      , 'C' , 4	, 0 } )
   AADD( aSTRUCT , { 'date'        , 'D' , 8	   , 0 } )
   AADD( aSTRUCT , { 'kz'          , 'C' , 1	   , 0 } )
   DBCREATE( "newtable.dbf" , aSTRUCT  )	  
ENDIF


OpenTables()
    

DEFINE WINDOW Form_1 ;
   AT 10,10          ;
   WIDTH 900         ;
   HEIGHT 1200        ;
   TITLE "Fahrer	"  ;
   MAIN 

   On Key F10 ACTION ende()  

   @ 10,10 GRID Grid_1 ;
   PARENT Form_1                           ;
   WIDTH 400                               ;
   HEIGHT 400                              ;
   value {1,1}         ;
   On DblClick test()   ;
   HEADERS {"Persnr","Name","Vorname","Strasse","PLZ","Ort"}      ;
   WIDTHS {50,100,100,100,50,100}                    ;
   ROWSOURCE "bbpers"  ;
   COLUMNFIELDS {"bbpers->persnr","bbpers->name","bbpers->vORname","bbpers->strASSE","bbpers->plz","bbpers->ort"} 
  
  
   @ 40, 600 BUTTON button_1       ;
   PARENT form_1            ;
   CAPTION "Ende F-10"   ;
   WIDTH 200                 ;
   HEIGHT 50                 ;
   ONCLICK form_1.release
  
   //SetProperty('Form_1', 'button_1', 'Visible', .f.)
END WINDOW
   
ACTIVATE WINDOW Form_1

RETURN NIL
   
  



procedure OpenTables()
USE bbpers

index on name+vorname to nvname
return nil






function test
//SetProperty('Form_1', 'button_1', 'Visible', .t.)
SetProperty('Form_1', 'Grid_1','Visible', .F.)
go Form_1.Grid_1.RecNo

//MsgInfo (bbpers->persnr + bbpers->name + str(Form_1.Grid_1.RecNo))

cPERSNR := bbpers->persnr
SetProperty('Form_1', 'Grid_1','Visible', .T.)
//SetProperty('Form_1', 'button_1', 'Visible', .f.)
Form_1.Grid_1.SetFocus

IF IsControlDefined ('X1' , 'FORM_1' )  
   DoMethod ('FORM_1' , 'X1' , 'Release' )   
ENDIF

IF IsControlDefined ('X2' , 'FORM_1' )  
   DoMethod ('FORM_1' , 'X2' , 'Release' )   
ENDIF

IF IsControlDefined ('X3' , 'FORM_1' )  
   DoMethod ('FORM_1' , 'X3' , 'Release' )   
ENDIF

IF IsControlDefined ('X4' , 'FORM_1' )  
   DoMethod ('FORM_1' , 'X4' , 'Release' )   
ENDIF

aKZ := {'C', 'F', 'Z'}

DEFINE TEXTBOX    X1
   PARENT         FORM_1
   ROW            420
   COL            10
   WIDTH          100 
   HEIGHT         25
   VALUE          ALLTRIM(cPERSNR)
   FONTCOLOR      BLACK   
   TOOLTIP        '  '
   TABSTOP        .T. 
   READONLY       .T.
END TEXTBOX

DEFINE COMBOBOX   X2   
   PARENT         FORM_1
   ROW            420
   COL            120
   WIDTH          60 
   ITEMS          aKZ
   VALUE          1  
END COMBOBOX

 
DEFINE DATEPICKER X3
   PARENT         FORM_1
   ROW            420 
   COL            200
   WIDTH          150
   HEIGHT         30
   VALUE          DATE()
   SHOWNONE       .T.
END DATEPICKER

@ 420, 370 BUTTON X4       ;
   PARENT form_1           ;
   CAPTION "OK"            ;
   WIDTH 80                 ;
   HEIGHT 30                 ;
   ONCLICK        SAVE_ETC()
 
RETURN





function ende
form_1.release
hb_setcodepage('DEWIN')

return




FUNCTION SAVE_ETC()
/******************/
// RETRIEVE INPUT VALUES
c1 := FORM_1.X1.Value 
c2 := FORM_1.X2.DisplayValue 
c3 := FORM_1.X3.Value 

USE newtable NEW
APPEND BLANK
REPLACE  persnr      WITH  ALLTRIM(c1)
REPLACE  date        WITH  c3
REPLACE  KZ          WITH  c2
 
CLOSE newtable

SELECT bbpers

IF IsControlDefined ('X1' , 'FORM_1' )  
   DoMethod ('FORM_1' , 'X1' , 'Release' )   
ENDIF

IF IsControlDefined ('X2' , 'FORM_1' )  
   DoMethod ('FORM_1' , 'X2' , 'Release' )   
ENDIF

IF IsControlDefined ('X3' , 'FORM_1' )  
   DoMethod ('FORM_1' , 'X3' , 'Release' )   
ENDIF

IF IsControlDefined ('X4' , 'FORM_1' )  
   DoMethod ('FORM_1' , 'X4' , 'Release' )   
ENDIF
RETURN
Let me know!

Serge

ROBROS
Posts: 88
Joined: Thu May 25, 2017 6:30 pm
DBs Used: DBF
Has thanked: 36 times
Been thanked: 7 times

Post by ROBROS » Mon Dec 11, 2017 9:56 am

Thank you Serge,

I will try out, when I'm back from work.

Have a nice day.
Robert

User avatar
serge_girard
Posts: 2030
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Has thanked: 378 times
Been thanked: 87 times
Contact:

Post by serge_girard » Mon Dec 11, 2017 10:18 am

Thx, you too !

Serge

Post Reply