Page 1 of 1

How to make specificed item on the first row?

Posted: Fri Sep 17, 2010 2:58 pm
by huangchenmin
Hello everyone:
I add 40 items to GRID_1, and 10 items is visible at one time. There is a text to get the key from user. I wanna the item ,in which match the key to be on the first row of GRID_1. Tried several times and could find the way done. Please Help!

Re: How to make specificed item on the first row?

Posted: Fri Sep 17, 2010 3:51 pm
by Rathinagiri
It is not implemented in HMG.

However it is possible to do that using an UDF.

Please add this code to your application and call this function whenever you change the value of the grid or even you can set 'on change makevaluefirstitem("Form_1","Grid_1")'

Tell me whether it works. It is taken from my very old application. :)

Code: Select all


function MakeValueFirstItem(cParentWindowName,cGridControlName)
local ControlHandle := GetControlHandle (cGridControlName,cParentWindowName)
local nValue := 0
nValue := GetProperty( cParentWindowName,cGridControlName,"VALUE" )
If nValue > 0
   GridMakeFirst(ControlHandle,nValue)
Endif   
return nil


#pragma BEGINDUMP

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

HB_FUNC ( GRIDMAKEFIRST )
{
   HWND hWnd1;
   int value1,scroll1,top1;
   POINT pt1,pt2;
   hWnd1 = (HWND) hb_parnl (1);
   value1 = (int) hb_parni (2);
   top1 = SendMessage((HWND) hWnd1,LVM_GETTOPINDEX,(WPARAM) (int) 0,(LPARAM) (int) 0);
   top1++;
   SendMessage((HWND) hWnd1,LVM_GETITEMPOSITION,(WPARAM) (int) top1,(LPARAM) &pt1);
   SendMessage((HWND) hWnd1,LVM_GETITEMPOSITION,(WPARAM) (int) value1,(LPARAM) &pt2);
   scroll1 = pt2.y - pt1.y;
   SendMessage((HWND) hWnd1,LVM_SCROLL,(WPARAM)(int) 0,(LPARAM)(int) scroll1);
}
#pragma ENDDUMP


Re: How to make specificed item on the first row?

Posted: Fri Sep 17, 2010 5:04 pm
by huangchenmin
rathinagiri wrote:It is not implemented in HMG.

However it is possible to do that using an UDF.

Please add this code to your application and call this function whenever you change the value of the grid or even you can set 'on change makevaluefirstitem("Form_1","Grid_1")'

Tell me whether it works. It is taken from my very old application. :)

Code: Select all


function MakeValueFirstItem(cParentWindowName,cGridControlName)
local ControlHandle := GetControlHandle (cGridControlName,cParentWindowName)
local nValue := 0
nValue := GetProperty( cParentWindowName,cGridControlName,"VALUE" )
If nValue > 0
   GridMakeFirst(ControlHandle,nValue)
Endif   
return nil


#pragma BEGINDUMP

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

HB_FUNC ( GRIDMAKEFIRST )
{
   HWND hWnd1;
   int value1,scroll1,top1;
   POINT pt1,pt2;
   hWnd1 = (HWND) hb_parnl (1);
   value1 = (int) hb_parni (2);
   top1 = SendMessage((HWND) hWnd1,LVM_GETTOPINDEX,(WPARAM) (int) 0,(LPARAM) (int) 0);
   top1++;
   SendMessage((HWND) hWnd1,LVM_GETITEMPOSITION,(WPARAM) (int) top1,(LPARAM) &pt1);
   SendMessage((HWND) hWnd1,LVM_GETITEMPOSITION,(WPARAM) (int) value1,(LPARAM) &pt2);
   scroll1 = pt2.y - pt1.y;
   SendMessage((HWND) hWnd1,LVM_SCROLL,(WPARAM)(int) 0,(LPARAM)(int) scroll1);
}
#pragma ENDDUMP

Thank you very much.
I will try and reply to you ASAP.
Best Regards
chen min