ColumnOnHeadClick setting

Moderator: Rathinagiri

Post Reply
User avatar
hmgchang
Posts: 273
Joined: Tue Aug 13, 2013 4:46 am
Location: Indonesia

ColumnOnHeadClick setting

Post by hmgchang »

Hola Master,
I tried to modify the Grid1 on sample\Controls :

Code: Select all

/*
* HMG Hello World Demo
* (c) 2002 Andrea M.
*/

#include "hmg.ch"

Function Main

Local aRows [20] [3]

	DEFINE WINDOW Form_1 ;
		AT 0,0 ;
		WIDTH 800 ;
		HEIGHT 550 ;
		TITLE 'Hello World!' ;
    ON INIT Form_1_OnInit();
		MAIN 

		aRows [1]	:= {'Simpson','Homer','555-5555'}
		aRows [2]	:= {'Mulder','Fox','324-6432'} 
		aRows [3]	:= {'Smart','Max','432-5892'} 
		aRows [4]	:= {'Grillo','Pepe','894-2332'} 
		aRows [5]	:= {'Kirk','James','346-9873'} 
		aRows [6]	:= {'Barriga','Carlos','394-9654'} 
		aRows [7]	:= {'Flanders','Ned','435-3211'} 
		aRows [8]	:= {'Smith','John','123-1234'} 
		aRows [9]	:= {'Pedemonti','Flavio','000-0000'} 
		aRows [10]	:= {'Gomez','Juan','583-4832'} 
		aRows [11]	:= {'Fernandez','Raul','321-4332'} 
		aRows [12]	:= {'Borges','Javier','326-9430'} 
		aRows [13]	:= {'Alvarez','Alberto','543-7898'} 
		aRows [14]	:= {'Gonzalez','Ambo','437-8473'} 
		aRows [15]	:= {'Batistuta','Gol','485-2843'} 
		aRows [16]	:= {'Vinazzi','Amigo','394-5983'} 
		aRows [17]	:= {'Pedemonti','Flavio','534-7984'} 
		aRows [18]	:= {'Samarbide','Armando','854-7873'} 
		aRows [19]	:= {'Pradon','Alejandra','???-????'} 
		aRows [20]	:= {'Reyes','Monica','432-5836'} 

		@ 10,10 GRID Grid_1 ;
			WIDTH 760 ;
			HEIGHT 240 ;
			HEADERS {'Last Name','First Name','Phone'} ;
			WIDTHS {140,140,140};
			ITEMS aRows ;
			VALUE {1,1} ;
			TOOLTIP 'Editable Grid Control' ;
			EDIT ;
	                JUSTIFY { GRID_JTFY_CENTER,GRID_JTFY_RIGHT, GRID_JTFY_RIGHT } ;
			CELLNAVIGATION 


		@ 250,10 GRID Grid_2 ;
			WIDTH 760 ;
			HEIGHT 240 ;
			HEADERS {'Last Name','First Name','Phone'} ;
			WIDTHS {140,140,140};
			ITEMS aRows ;
			VALUE 1 EDIT ;
			TOOLTIP 'Editable Grid Control' ;
     	JUSTIFY { GRID_JTFY_LEFT,GRID_JTFY_CENTER, GRID_JTFY_CENTER } 
// ON HEADCLICK { {||MsgInfo('Click 1')} , {||MsgInfo('Click 2')} , {||MsgInfo('Click 3')} } ;
      

	END WINDOW

	CENTER WINDOW Form_1

	ACTIVATE WINDOW Form_1

Return

FUNCTION Form_1_OnInit()
  LOCAL nI
  FOR nI := 1 TO 3
    SetProperty( "Form_1", "Grid_2", "ColumnOnHeadClick", nI, {|| msgInfo( "Click" + PADL( nI, 2))})
  NEXT
  RETURN NIL

Run trial and any column header i click always get the same :
grid1.JPG
grid1.JPG (70.08 KiB) Viewed 1522 times
What have i done wrong, Pls advise

2. How to get the column number which we click on the columnheader ?

Thks n rgds
Chang
Just Hmg It !
User avatar
hmgchang
Posts: 273
Joined: Tue Aug 13, 2013 4:46 am
Location: Indonesia

Re: ColumnOnHeadClick setting

Post by hmgchang »

I found Mol solution :
oncolumheaderclick.JPG
oncolumheaderclick.JPG (41.13 KiB) Viewed 1496 times
Thank you very much Mr. Mol....
You are very helpful as always....

Thks n Rgds
Chang
Just Hmg It !
User avatar
gfilatov
Posts: 1060
Joined: Fri Aug 01, 2008 5:42 am
Location: Ukraine
Contact:

Re: ColumnOnHeadClick setting

Post by gfilatov »

hmgchang wrote: Fri Apr 09, 2021 6:38 am
What have i done wrong, Pls advise
Hello Chang,

Please try the updated function below:

Code: Select all

FUNCTION Form_1_OnInit()
  LOCAL nI
  FOR nI := 1 TO 3
    SetProperty( "Form_1", "Grid_2", "ColumnOnHeadClick", nI, &('{|| msgInfo( "Click "+hb_ntos( ' + hb_ntos( nI ) + '))}') )
  NEXT
  RETURN NIL
Hope that helps :idea:
Kind Regards,
Grigory Filatov

"Everything should be made as simple as possible, but no simpler." Albert Einstein
User avatar
AUGE_OHR
Posts: 2060
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: ColumnOnHeadClick setting

Post by AUGE_OHR »

hi,

have a look into c:\hmg.3.4.4\SOURCE\H_GRID.PRG
you will find _HMG_SYSDATA where 1-40 hold Information of Control

Code: Select all

   _HMG_SYSDATA[ 7 ] [ k ] := aHeaders
   _HMG_SYSDATA[ 17 ] [ k ] := aHeadClick
   ...
   _HMG_SYSDATA[ 33 ] [ k ] := aHeaders
not sure if 7 or 33 have Array of "Headers"

---

Code: Select all

   HEADERS { 'Name', 'Size', 'Date', 'Time', 'Attr' } ;
   ON HEADCLICK { { || HeadLeft( F_NAME ) }, { || HeadLeft( F_SIZE ) }, { || HeadLeft( F_DATE ) }, { || HeadLeft( F_TIME ) }, { || HeadLeft( F_ATTR ) } } ;
2 x Solution

a.) each Header Position have a own Codeblock
or.
b.) you can ASCAN() Name of Header to get Header Position in Array
have fun
Jimmy
User avatar
hmgchang
Posts: 273
Joined: Tue Aug 13, 2013 4:46 am
Location: Indonesia

Re: ColumnOnHeadClick setting

Post by hmgchang »

gfilatov wrote: Fri Apr 09, 2021 8:51 am
hmgchang wrote: Fri Apr 09, 2021 6:38 am
What have i done wrong, Pls advise
Hello Chang,

Please try the updated function below:

Code: Select all

FUNCTION Form_1_OnInit()
  LOCAL nI
  FOR nI := 1 TO 3
    SetProperty( "Form_1", "Grid_2", "ColumnOnHeadClick", nI, &('{|| msgInfo( "Click "+hb_ntos( ' + hb_ntos( nI ) + '))}') )
  NEXT
  RETURN NIL
Hope that helps :idea:
Thks Master GFilatov, i hv tried and it works...
working with codeblock sometimes we hv to be carefull....



Thks n Rgds
Chang
Just Hmg It !
User avatar
hmgchang
Posts: 273
Joined: Tue Aug 13, 2013 4:46 am
Location: Indonesia

Re: ColumnOnHeadClick setting

Post by hmgchang »

AUGE_OHR wrote: Fri Apr 09, 2021 8:55 am hi,

have a look into c:\hmg.3.4.4\SOURCE\H_GRID.PRG
you will find _HMG_SYSDATA where 1-40 hold Information of Control

Code: Select all

   _HMG_SYSDATA[ 7 ] [ k ] := aHeaders
   _HMG_SYSDATA[ 17 ] [ k ] := aHeadClick
   ...
   _HMG_SYSDATA[ 33 ] [ k ] := aHeaders
not sure if 7 or 33 have Array of "Headers"

---

Code: Select all

   HEADERS { 'Name', 'Size', 'Date', 'Time', 'Attr' } ;
   ON HEADCLICK { { || HeadLeft( F_NAME ) }, { || HeadLeft( F_SIZE ) }, { || HeadLeft( F_DATE ) }, { || HeadLeft( F_TIME ) }, { || HeadLeft( F_ATTR ) } } ;
2 x Solution

a.) each Header Position have a own Codeblock
or.
b.) you can ASCAN() Name of Header to get Header Position in Array
Thks Jimmy...
I hv to modify the number of columns base on the users choice ( which field to display),
and i need to sort the grid base on the click on the columnHeader
just like in the TC.
2. After use click on the column header, i need to change the header
with an image ( arrow up/down) to indicate the sort is A-z/z-A.

I am happy and open for any suggestion.


Thks n Rgds
Chang
Just Hmg It !
Post Reply