combobox in grid

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

franco
Posts: 297
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Been thanked: 9 times

combobox in grid

Post by franco » Tue Oct 23, 2018 6:08 pm

I am trying to have a combobox in my grid so I can change contents from a tables field.
I am using a table for the grid. Grid has 2 columns. and both columnwhen set to .t. .
columncontrols are {||{'textbox', 'character','!!!!!!!!!'}, {'combobox'}}
combobox will not drop down and has no drop arrow. Contents are correct but can not change.
Anybody know what am I doing wrong.
Thanks in advance ....... Franco
Franco Bushie
Canada

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

Post by andyglezl » Tue Oct 23, 2018 7:05 pm

Hi Franco

Maybe you're missing the data to select ...
{'COMBOBOX',{'One','Two','Three'}}
Andrés González López
Desde Guadalajara, Jalisco. México.

franco
Posts: 297
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Been thanked: 9 times

Post by franco » Tue Oct 23, 2018 7:13 pm

Andy could I use field name like {'combobox',fieldname} .or. {'combobox', 'fieldname'} .or. {'combobox', &fieldname}.
I have the columnfields set to fieldnames.
I tried the first two. I will try again.
Thanks Franco
Franco Bushie
Canada

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

Post by andyglezl » Tue Oct 23, 2018 7:38 pm

You must load in an array, the data to select.

Sample...

DBUSEAREA( .T., "DBFNTX", "CLIENTES", "CTES", .T., .F. )
aNomCpos := {}
AEVAL( DBSTRUCT( "CTES" ), { | aField | AADD( aNomCpos, aField[ DBS_NAME ] ) } )

{ 'COMBOBOX', aNomCpos }
Andrés González López
Desde Guadalajara, Jalisco. México.

franco
Posts: 297
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Been thanked: 9 times

Post by franco » Wed Oct 24, 2018 10:37 am

Is there a way to put a tooltip on the header of a grid.
??? headers { || {'One' tooltip "Click For"}, {'Two' tooltip "Click For"} }
This way I can make a simple function from head click with a browse or combobox to change the field from a pick list.
Franco Bushie
Canada

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

Post by andyglezl » Wed Oct 24, 2018 12:51 pm

@ <nRow> ,<nCol> GRID <ControlName> [ OF | PARENT <ParentWindowName> ]

ON HEADCLICK <abBlock>

El ejemplo anterior tambien es muy simple y funcional...

No te funcionó lo del ejemplo ?
Porque no posteas tu prg ?
-----------------------------------------------

The previous example is also very simple and functional ...

Did not the example work for you?
Why do not you post your prg?
Andrés González López
Desde Guadalajara, Jalisco. México.

franco
Posts: 297
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Been thanked: 9 times

Post by franco » Wed Oct 24, 2018 4:05 pm

I know how to use on headclick but want the program operator to know what to click with a tooltip, but a tooltip for the whole grid is always
in the way. I just wanted a tooltip for the headers. I could put an empty lablel just above the headers of the grid with a tooltip, a bit messy.
I do not quite know how to follow your example. I like to use a table in the grid. I am not sure how to combine a table and a array from another
table that links in a grid.
I will create a small program example for you.
Thanks Andy
Franco Bushie
Canada

franco
Posts: 297
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Been thanked: 9 times

Post by franco » Wed Oct 31, 2018 4:20 pm

This is my solution, but I have another problem.

I have clients who , after a busy day start to loose the caption in their buttons.
If I compile this program 30 times in windows 10 hmg 3.44 I get a message PROGRAM ERROR and the computer freezes. I need to ctrl,alt del to
close IDE. One time, and I find it hard to repeat, but at about compile 28 ? I went to X out of IDE and my are you sure button captions where blank.
Any thoughts, I think somehow I am building up in memory. I tried different things at this program release to no avail.
Dr. Claudio mentioned in a previous post about do not do final compile with Incremental data on I do not understand this, causes strange behavior.

Code: Select all

#include <hmg.ch>


*--------------------------------------------------------*
Function Main()
*--------------------------------------------------------*

Createtable()
Select PINV_IT

   DEFINE WINDOW Form_1 ;
      AT 0,0 ;
      WIDTH 640 HEIGHT 480 ;
      TITLE 'Combo Test' ;
      MAIN NOMAXIMIZE ;
      ON RELEASE CLOSETABLES()

      DEFINE MAIN MENU
         DEFINE POPUP 'Test'
            ITEM "Exit"      ACTION  {||{ThisWindow.Release()}}
         END POPUP
      END MENU
	@ 0,10 label label_1 ;
	WIDTH 610 ;
	HEIGHT 30 ;
	TRANSPARENT ;
	VALUE '' ;
 	TOOLTIP 'Highlight Group to Change and Click Header3 to Change Group or Highlite Cost to Change and Hit Enter'

	@ 260,10 button button_1 ;
	caption 'Exit' ; 
	action  {||{ThisWindow.Release()}}
	
      DEFINE GRID grid_1   
	 ROW	30
	 COL	10 
         WIDTH 610   
         HEIGHT 220     
         HEADERS { 'Inv' , 'Item' , 'Group', 'Cost' } 
         WIDTHS { 100 , 100 , 100, 100 } 
	VALUE 1
	 COLUMNFIELDS { 'Inv_no' , 'Item_no' , 'Group' , 'Cost'} 
	 COLUMNCONTROLS { {'TEXTBOX','CHARACTER','!!!!!!!!'},{'TEXTBOX','CHARACTER','!!!!!!!!!!!!!!!'},;
				{'TEXTBOX'},{'TEXTBOX','NUMERIC','9999999.99'} }
	 ONHEADCLICK { {|| '' }, {|| '' },{|| CHANGEGROUP() }, {|| '' }, }
         ROWSOURCE "pinv_it" 
 	 ALLOWEDIT .T.  
         COLUMNFIELDS { 'Inv_no' , 'Item_no' , 'Group' , 'Cost'}
         COLUMNWHEN { { || .F. },{ || .F. },{ || .F. },{ || .T. } } 
	 ON CHANGE  { ||{invprsave() } }  
      END GRID 
	 	


   END WINDOW
	FORM_1.GRID_1.REFRESH()
   CENTER WINDOW Form_1

   ACTIVATE WINDOW Form_1

Return nil


*--------------------------------------------------------*
Procedure CloseTables
*--------------------------------------------------------*

		close PINV_IT
		release PINV_IT
		dbdrop('pinv_it')        // DOES NOT HELP LOCKUP
		close GROUP
		release GROUP         
		dbdrop('group')
		RELEASE MEMORY    // DOES NOT HELP LOCKUP
		close all                   // DOES NOT HELP LOCKUP
		clear all                    // DOES NOT HELP LOCKUP

Return

*--------------------------------------------------------*
Function CreateTable
*--------------------------------------------------------*

 Local CF1 := {}, TEMP := 1
		CF1 := {}
		aADD(CF1,{'INV_NO' , 'C' , 8,0})
		AADD(CF1,{'ITEM_NO', 'C' , 15,0})
		Aadd(CF1,{'GROUP',   'C', 15,0})
		Aadd(CF1,{'COST', 'N' , 10,2})

		if ! hb_dbcreatetemp("PINV_IT", cf1)
			msgbox("Cannot create temporary table: Item")
			RELEASE WINDOW ALL
			return nil
		endif
		if select("PINV_IT") = 0
			use PINV_IT new
		endif
		select PINV_IT 
		index on inv_no to PINV_IT
		do while temp < 10
			append blank
			replace inv_no with 'IN'+alltrim(str(temp+1000))
			replace item_no with 'IT'+alltrim(str(temp+100))
			replace cost with temp*100
			replace GROUP with 'PARTS'
			temp:=temp+1
			loop
		enddo

		CF1 := {}
		aADD(CF1,{'GROUP' , 'C' , 15, 0} )

		if ! hb_dbcreatetemp("GROUP", cf1)
			msgbox("Cannot create temporary table: Item")
			RELEASE WINDOW ALL
			return nil
		endif
		if select("GROUP") = 0
			use GROUP new
		endif
		select GROUP
		append blank
		replace GROUP with 'PARTS'
		append blank
		replace GROUP with 'LABOUR'
Return Nil


*------------------------------------------------------------------------------*
Function Invprsave
*------------------------------------------------------------------------------*
local ctot := 0, stot := 0, rec := recno(), acellpr
	acellpr := Form_1.Grid_1.value
	*Form_1.grid_1.save
	if alias() = 'GROUP'
		SELECT PINV_IT
		go Form_1.Grid_1.recno
		REPLACE GROUP WITH GROUP->GROUP
		Form_1.Grid_1.REFRESH()
	ENDIF
	Form_1.grid_1.save
	sum cost to ctot
	Form_1.Grid_1.setfocus
	Form_1.Grid_1.VALUE := {acellpr[1],acellpr[2]}
	go Form_1.Grid_1.recno
return

*------------------------------------------------------------------------------*
Function Changegroup
*------------------------------------------------------------------------------*
	select GROUP
  IF .NOT. ISWINDOWACTIVE(grbrw)
	
	DEFINE WINDOW grbrw ;
		AT  110,10 ; //R1+80, C1+10 ;
		WIDTH 300;      //GetDesktopWidth() * 0.75 ;
		HEIGHT 300 ;  // GetDesktopHeight() * 0.75 ;
		TITLE 'Press Escape to Exit' ;
		MODAL ;
		NOSIZE  ;
		SYSMENU .t. ;
   	   	ON RELEASE Invprsave() 

	
	DEFINE BROWSE gbrw
		ROW 10    
		COL 20     
		WIDTH 130
		HEIGHT 290
		BACKCOLOR {181,205,106}     //{180,62,60}
		*BACKCOLOR    { 180, 180, 200}
		FONTCOLOR { 0, 0, 0 }
		HEADERS  {'Group' }
		WIDTHS   {100}
		WORKAREA  GROUP  //inv
		FIELDS { 'GROUP'}
		VALUE 1
		READONLY .T.
		VSCROLLBAR .T.
 		ONDBLCLICK { || dbgoto(THIS.VALUE),  grbrw.release }
	END BROWSE

	END WINDOW
        CENTER WINDOW grbrw
        ACTIVATE WINDOW grbrw
  ELSE
	RETURN
  ENDIF

Return nil

Thanks in advance ..... Franco
Franco Bushie
Canada

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

Post by andyglezl » Wed Oct 31, 2018 7:08 pm

Bueno, a mi me gusta hacer las cosas minimalistas.
Y esta sería la forma en como yo lo haría, espero te sirva.
*------------------------------------------------------------------
Well, I like to do minimalist things.
And this would be the way I would do it, I hope it helps you.
ComboBTest.png
ComboBTest.png (39.93 KiB) Viewed 336 times

Code: Select all


#include <hmg.ch>

*--------------------------------------------------------*
Function Main()
*--------------------------------------------------------*

	Createtable()
	Select PINV_IT

   DEFINE WINDOW Form_1 ;
      AT 0,0 ;
      WIDTH 640 HEIGHT 480 ;
      TITLE 'Combo Test' ;
      MAIN NOMAXIMIZE ;
      ON RELEASE CLOSETABLES()

      DEFINE MAIN MENU
         DEFINE POPUP 'Test'
            ITEM "Exit"      ACTION  {||{ThisWindow.Release()}}
         END POPUP
      END MENU
*	@ 0,10 label label_1 ;
*	WIDTH 610 ;
*	HEIGHT 30 ;
*	TRANSPARENT ;
*	VALUE '' ;
* 	TOOLTIP 'Highlight Group to Change and Click Header3 to Change Group or Highlite Cost to Change and Hit Enter'

	@ 260,10 button button_1 ;
	caption 'Exit' ; 
	action  {||{ThisWindow.Release()}}
	
    DEFINE GRID grid_1   
		ROW	30
		COL	10 
        WIDTH 610   
        HEIGHT 220     
        HEADERS { 'Inv' , 'Item' , 'Group (Edit)', 'Cost (Edit)' } 					// <=========== CHANGE
        WIDTHS { 100 , 100 , 100, 100 } 
		VALUE 1
		COLUMNFIELDS { 'Inv_no' , 'Item_no' , 'Group' , 'Cost'} 
		COLUMNCONTROLS { 	{'TEXTBOX' ,'CHARACTER','!!!!!!!!'}			, ;
							{'TEXTBOX' ,'CHARACTER','!!!!!!!!!!!!!!!'}	, ;
							{'COMBOBOX',{'PARTS','LABOUR'} }			, ;			// <=========== CHANGE
							{'TEXTBOX' ,'NUMERIC','9999999.99'} }	
		; // ONHEADCLICK { {|| '' }, {|| '' },{|| CHANGEGROUP() }, {|| '' }, }		// <=========== NOT NECESSARY
		ROWSOURCE "pinv_it" 
		ALLOWEDIT .T.  
		; // COLUMNFIELDS { 'Inv_no' , 'Item_no' , 'Group' , 'Cost'}				// <===========  IT'S DUPLICATED !
		COLUMNWHEN { { || .F. },{ || .F. },{ || .T. },{ || .T. } } 					// <===========  CHANGE GROUP = .T.
		ON CHANGE  { ||{invprsave() } }  
	END GRID 
	 	


   END WINDOW
	FORM_1.GRID_1.REFRESH()
   CENTER WINDOW Form_1

   ACTIVATE WINDOW Form_1

Return nil


*--------------------------------------------------------*
Procedure CloseTables
*--------------------------------------------------------*

		//----------------------------------------------------------------		
		// PARA VER QUE PASA, YA QUE EL ARCHIVO ES TEMPORAL. 
		// TO SEE WHAT HAPPENS, SINCE THE ARCHIVE IS TEMPORARY.
		x:= ""
		GO TOP
		DO WHILE ! EOF()
			x := x + INV_NO + ' - ' + ITEM_NO + ' - ' + STR( GROUP ) + ' - ' + STR( COST ) + HB_OsNewLine()
			DBSKIP()
		ENDDO
		MSGBOX( x, "Lo Grabado/I saved it" )
		//----------------------------------------------------------------
		//----------------------------------------------------------------
	
		close PINV_IT
*		release PINV_IT
*		dbdrop('pinv_it')   // DOES NOT HELP LOCKUP
*		close GROUP
*		release GROUP         
*		dbdrop('group')
*		RELEASE MEMORY      // DOES NOT HELP LOCKUP
*		close all           // DOES NOT HELP LOCKUP
*		clear all           // DOES NOT HELP LOCKUP

Return

*--------------------------------------------------------*
Function CreateTable
*--------------------------------------------------------*

 Local CF1 := {}, TEMP := 1
		CF1 := {}
		aADD(CF1,{'INV_NO' , 'C' , 8,0})
		AADD(CF1,{'ITEM_NO', 'C' , 15,0})
		*Aadd(CF1,{'GROUP',   'C', 15,0})							// <=========== CHANGE "C" to "N"
		Aadd(CF1,{'GROUP',   'N', 1,0})
		Aadd(CF1,{'COST', 'N' , 10,2})

		if ! hb_dbcreatetemp("PINV_IT", cf1)
			msgbox("Cannot create temporary table: Item")
			RELEASE WINDOW ALL
			return nil
		endif
		if select("PINV_IT") = 0
			use PINV_IT new
		endif
		select PINV_IT 
		index on inv_no to PINV_IT
		do while temp < 10
			append blank
			replace inv_no with 'IN'+alltrim(str(temp+1000))
			replace item_no with 'IT'+alltrim(str(temp+100))
			replace cost with temp*100
*			replace GROUP with 'PARTS'								// <=========== CHANGE
			replace GROUP with 1
			temp:=temp+1
			loop
		enddo

*		CF1 := {}
*		aADD(CF1,{'GROUP' , 'C' , 15, 0} )
*
*		if ! hb_dbcreatetemp("GROUP", cf1)
*			msgbox("Cannot create temporary table: Item")
*			RELEASE WINDOW ALL
*			return nil
*		endif
*		if select("GROUP") = 0
*			use GROUP new
*		endif
*		select GROUP
*		append blank
*		replace GROUP with 'PARTS'
*		append blank
*		replace GROUP with 'LABOUR'
Return Nil


*------------------------------------------------------------------------------*
Function Invprsave
*------------------------------------------------------------------------------*
local ctot := 0, stot := 0, rec := recno(), acellpr
*	acellpr := Form_1.Grid_1.value
*	*Form_1.grid_1.save
*	if alias() = 'GROUP'
*		SELECT PINV_IT
*		go Form_1.Grid_1.recno
*		REPLACE GROUP WITH GROUP->GROUP
*		Form_1.Grid_1.REFRESH()
*	ENDIF
	Form_1.grid_1.save
	sum cost to ctot
*	Form_1.Grid_1.setfocus
*	Form_1.Grid_1.VALUE := {acellpr[1],acellpr[2]}
*	go Form_1.Grid_1.recno
return

/*

*------------------------------------------------------------------------------*
Function Changegroup
*------------------------------------------------------------------------------*
	select GROUP
  IF .NOT. ISWINDOWACTIVE(grbrw)
	
	DEFINE WINDOW grbrw ;
		AT  110,10 ; //R1+80, C1+10 ;
		WIDTH 300;      //GetDesktopWidth() * 0.75 ;
		HEIGHT 300 ;  // GetDesktopHeight() * 0.75 ;
		TITLE 'Press Escape to Exit' ;
		MODAL ;
		NOSIZE  ;
		SYSMENU .t. ;
   	   	ON RELEASE Invprsave() 

	
	DEFINE BROWSE gbrw
		ROW 10    
		COL 20     
		WIDTH 130
		HEIGHT 290
		BACKCOLOR {181,205,106}     //{180,62,60}
		*BACKCOLOR    { 180, 180, 200}
		FONTCOLOR { 0, 0, 0 }
		HEADERS  {'Group' }
		WIDTHS   {100}
		WORKAREA  GROUP  //inv
		FIELDS { 'GROUP'}
		VALUE 1
		READONLY .T.
		VSCROLLBAR .T.
 		ONDBLCLICK { || dbgoto(THIS.VALUE),  grbrw.release }
	END BROWSE

	END WINDOW
        CENTER WINDOW grbrw
        ACTIVATE WINDOW grbrw
  ELSE
	RETURN
  ENDIF

Return nil


*/

Andrés González López
Desde Guadalajara, Jalisco. México.

franco
Posts: 297
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Been thanked: 9 times

Post by franco » Wed Oct 31, 2018 7:29 pm

Andy,
I have to use group table as it is in my big program with up to 30 items. This works good for me as I have it laid out.
I like your idea to save or even not save changes.
Have you tried compiling my program 30 times to see if it locks your computer., or do you have any other thoughts on this problem.
Do I not have something installed properly in 3.44. I am going to compile in 3.2 to see if it locks up. Will let you all know.
Thanks again Andy
Franco Bushie
Canada

Post Reply