How to force Column(x) be visible in GRID

Topic Specific Tutorials and Tips.

Moderator: Rathinagiri

Post Reply
User avatar
Rathinagiri
Posts: 5266
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 171 times
Been thanked: 173 times
Contact:

How to force Column(x) be visible in GRID

Post by Rathinagiri » Sun Jun 06, 2010 11:30 am

How to determine GRID.Column(x) is visible in code?

We can verify the visible grid column width of any column using a small UDF get_grid_colwidth(controlname, parentform,nColumnNo). Please see the example below. If the value returned is 0, we can be sure that the column is not visible.

Code: Select all

#include "hmg.ch"

Function Main

	DEFINE WINDOW Form_1 ;
		AT 0,0 ;
		WIDTH 550 ;
		HEIGHT 400 ;
		TITLE 'Hello World!' ;
		MAIN

		DEFINE MAIN MENU
			DEFINE POPUP 'File'
				menuitem 'Get Width of second column' action msginfo(str(get_grid_colwidth("Grid_1","Form_1",2)))
			END POPUP
		END MENU
		

		DEFINE GRID Grid_1 
			ROW		10
			COL		10
			WIDTH		500 
			HEIGHT		330 
			HEADERS		{'Last Name','First Name','Phone'} 
			WIDTHS		{140,140,140}
			ITEMS		LoadItems() 
			VALUE		1
		END GRID

	END WINDOW

	Form_1.Center

	Form_1.Activate

Return

Function LoadItems()
Local aRows [20] [3]

	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'}

Return aRows


function get_grid_colwidth(ControlName,ParentForm,nColumn)
local c := GetControlHandle (ControlName,ParentForm)
return ListView_GetColumnWidth ( c , nColumn - 1 )
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.

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

Post by Rathinagiri » Mon Jun 07, 2010 7:11 am

We can use these functions to get and set the horizontal scroll positions of a grid. Using these functions and the column width info of all the columns, we can ensure the visibility of a column in a grid.
gethscrollposition(controlname,parentform)
sethscrollposition(controlname,parentform,npos)

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!' ;
		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 {600,200,200};
			ITEMS aRows ;
			VALUE 1 EDIT ;
			TOOLTIP 'Editable Grid Control' ;
			ON HEADCLICK { {||MsgInfo('Click 1')} , {||MsgInfo('Click 2')} , {||MsgInfo('Click 3')} } ;
                	JUSTIFY { GRID_JTFY_LEFT,GRID_JTFY_CENTER, GRID_JTFY_CENTER }
                   
    @ 500,10 button b1 caption "Get HScroll" action msginfo(str(gethscrollposition("Grid_2","Form_1")))
    @ 500,110 button b2 caption "Set HScroll" action sethscrollposition("Grid_2","Form_1",260)
	END WINDOW

	CENTER WINDOW Form_1

	ACTIVATE WINDOW Form_1

Return

function gethscrollposition(controlname,parentform)
local c := GetControlHandle (ControlName,ParentForm)
return get_hscroll_pos(c)

function sethscrollposition(controlname,parentform,nPos)
local c := GetControlHandle (ControlName,ParentForm)
set_hscroll_pos(c,nPos,GetFormHandle(parentform))
return nil


#pragma BEGINDUMP

#include <windows.h>
#include <commctrl.h>
#include "hbapi.h"
#include <wingdi.h>

HB_FUNC ( GET_HSCROLL_POS )

{
   HWND hWnd1;
   hWnd1 = (HWND) hb_parnl (1);
   hb_retni(GetScrollPos(hWnd1, SB_HORZ));
   }
   
HB_FUNC ( SET_HSCROLL_POS )

{
   HWND hWnd1;
   hWnd1 = (HWND) hb_parnl (1);
   SendMessage(hWnd1,LVM_SCROLL,hb_parni(2),0);

     }
      
#pragma ENDDUMP

East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.

User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil
Has thanked: 100 times
Been thanked: 182 times

Post by Pablo César » Thu Dec 11, 2014 11:55 pm

Just to let my experience shared in this same goal.

I used in TableMaker:

_HMG_GRID_KBDSCROLL(GetControlIndex("Grid_1","Form_2"))

And works fine for me.
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein

User avatar
srvet_claudio
Posts: 2044
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Has thanked: 35 times
Been thanked: 147 times
Contact:

Post by srvet_claudio » Fri Dec 12, 2014 7:06 am

My two cents!

Set/Get:
<ParentWindowName>.<GridControlName>.ColumnWIDTH ( nColIndex ) --> nColumnWidth

HMG functions:

GetScrollPos (hwnd, SB_HORZ)
GetScrollPos (hwnd, SB_VERT)

SetScrollPos (hwnd, SB_HORZ, nPos, lRedraw)
SetScrollPos (hwnd, SB_VERT, nPos, lRedraw)

#define SB_HORZ 0
#define SB_VERT 1
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com

User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil
Has thanked: 100 times
Been thanked: 182 times

Post by Pablo César » Fri Dec 12, 2014 11:20 am

Thank you Claudio ! :)
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein

Post Reply