i try to calculate Size of GRID ... but something is wrong with my calculation
i use Arial 11 and this line
Code: Select all
nHeight := ( iMax + 1 ) * 22.3
so i need a better Way for "calculation" height of GRID.
please help, thx
Moderator: Rathinagiri
Code: Select all
nHeight := ( iMax + 1 ) * 22.3
that is exact what i wonder when it does not fit any more ...serge_girard wrote: ↑Tue Feb 04, 2020 8:17 am ... but when more than 30 or 40 the form height doesn't fit on the screen so the last records can not be seen.
Code: Select all
HB_FUNC( GETTEXTHEIGHT ) // returns the Height of a string in pixels
Hi Jimmy,
Code: Select all
*+--------------------------------------------------------------------
*+
*+ Source Module => c:\hmg.3.4.4\0\GRIDHIGH\\MODISTRU.PRG
*+
*+ Copyright(C) 1983-2020 by Auge & Ohr
*+
*+ Functions: Procedure main()
*+ Static Procedure SaveCreate()
*+ Static Procedure CloseForm2()
*+
*+ Tables: USE ( cDbf )
*+
*+ Reformatted by Click! 2.05.30 on Feb-4-2020 at 8:34 am
*+
*+--------------------------------------------------------------------
#include "HMG.CH"
#include "Dbstruct.ch"
*+--------------------------------------------------------------------
*+
*+ Procedure main()
*+
*+--------------------------------------------------------------------
*+
PROCEDURE main( cDbf )
LOCAL aStruc, i, iMax
LOCAL aCaption := { "Name", "Type", "Len", "Dec" }
LOCAL aWide := { 110, 50, 60, 60 }
LOCAL aItems := {}
LOCAL nHeight := 0
LOCAL nTitlebar := GETTITLEHEIGHT()
default cDBF := "TEST.dbf"
IF !FILE( cDbf )
msginfo( "need DBF" )
RETURN
ENDIF
ALTD()
USE ( cDbf )
aStruc := DBSTRUCT()
iMax := LEN( aStruc )
nHeight := ( iMax + 1 ) * 22.3
FOR i := 1 TO iMax
AADD( aItems, { aStruc[ i ] [ DBS_NAME ], ;
aStruc[ i ] [ DBS_TYPE ], ;
aStruc[ i ] [ DBS_LEN ], ;
aStruc[ i ] [ DBS_DEC ] } )
NEXT
DEFINE WINDOW Form_2 ;
AT 0, 0 ;
WIDTH 330 ;
HEIGHT nHeight + nTitlebar + 40 + 50 ;
TITLE cDbf ;
MAIN ;
ON RELEASE CloseForm2() ;
FONT "Arial" ;
SIZE 11 ;
NOMINIMIZE ;
NOMAXIMIZE ;
NOSIZE
DEFINE TOOLBAR oTOOLBAR BUTTONSIZE 50, 50 FLAT BORDER
BUTTON oBtSave ;
TOOLTIP "F5: create DBF" ;
ACTION SaveCreate()
END TOOLBAR
DEFINE GRID Brow_2
PARENT Form_2
ROW 10 + 50
COL 10
WIDTH 290
HEIGHT nHeight
HEADERS aCaption
WIDTHS aWide
ITEMS aItems
FONTNAME "Arial"
FONTSIZE 11
VALUE 1
END GRID
END WINDOW
Form_2.Brow_2.height := GetHeght_ListView(Form_2.Brow_2.HANDLE, iMax)
Form_2.height := Form_2.Brow_2.row + Form_2.Brow_2.height + GetTitleHeight() + 2*GetBorderHeight() + 10
Form_2.Title := (Form_2.Title) + ' -> # visible rows: ' + hb_ntos(GetNumOfVisibleRows('Brow_2', 'Form_2'))
ON KEY F5 OF Form_2 ACTION SaveCreate()
ON KEY ESCAPE OF Form_2 ACTION Form_2.Release
// Form_2.Brow_2.setfocus
CENTER WINDOW Form_2
ACTIVATE WINDOW Form_2
RETURN
Function GetNumOfVisibleRows ( ControlName , ParentForm )
LOCAL i
i := GetControlIndex ( ControlName , ParentForm )
Return ListviewGetCountPerPage ( GetControlHandleByIndex( i ) )
FUNCTION GetHeght_ListView( hBrw, nRows ) // height Grid \ Browse on the number of rows
LOCAL a
a := ListViewApproximateViewRect( hBrw, nRows - 1 ) // { Width, Height }
a[1] += Round( GetBorderWidth () / 2, 0 ) // Width
a[2] += Round( GetBorderHeight() / 2, 0 ) // Height
RETURN a[2]
#pragma BEGINDUMP
#include <mgdefs.h>
#include <commctrl.h>
HB_FUNC( LISTVIEWAPPROXIMATEVIEWRECT )
{
int iCount = hb_parni( 2 );
DWORD Rc;
Rc = ListView_ApproximateViewRect( ( HWND ) hb_parnl( 1 ), -1, -1, iCount );
hb_reta( 2 );
HB_STORNI( LOWORD( Rc ), -1, 1 );
HB_STORNI( HIWORD( Rc ), -1, 2 );
}
#pragma ENDDUMP
*+--------------------------------------------------------------------
*+
*+ Static Procedure SaveCreate()
*+
*+ Called from ( modistru.prg ) 2 - procedure main()
*+
*+--------------------------------------------------------------------
*+
STATIC PROCEDURE SaveCreate( cOutPutDBF, aNew, aHead, nRowStart, nRowEnd, nColEnd, lDone, aType )
RETURN
*+--------------------------------------------------------------------
*+
*+ Static Procedure CloseForm2()
*+
*+ Called from ( modistru.prg ) 1 - procedure main()
*+
*+--------------------------------------------------------------------
*+
STATIC PROCEDURE CloseForm2()
RETURN
*+ EOF: MODISTRU.PRG
THX for your Solution.
Hi Jimmy,
to a standard Grid control in MiniguiEx.AUTOSIZEHEIGHT <nRow> and AUTOSIZEWIDTH <.T.|.F.>
Code: Select all
*+--------------------------------------------------------------------
*+
*+ Source Module => c:\hmg.3.4.4\0\GRIDHIGH\\MODISTRU.PRG
*+
*+ Copyright(C) 1983-2020 by Auge & Ohr
*+
*+ Functions: Procedure main()
*+ Static Procedure SaveCreate()
*+ Static Procedure CloseForm2()
*+
*+ Tables: USE ( cDbf )
*+
*+ Reformatted by Click! 2.05.30 on Feb-4-2020 at 8:34 am
*+
*+--------------------------------------------------------------------
#include "HMG.CH"
#include "Dbstruct.ch"
*+--------------------------------------------------------------------
*+
*+ Procedure main()
*+
*+--------------------------------------------------------------------
*+
PROCEDURE main( cDbf )
LOCAL aStruc, i, iMax
LOCAL aCaption := { "Name", "Type", "Len", "Dec" }
LOCAL aWide := { 110, 50, 60, 60 }
LOCAL aItems := {}
LOCAL nHeight := 0
LOCAL nTitlebar := GETTITLEHEIGHT()
default cDBF := "TEST.dbf"
IF !FILE( cDbf )
msginfo( "need DBF" )
RETURN
ENDIF
ALTD()
USE ( cDbf )
aStruc := DBSTRUCT()
iMax := LEN( aStruc )
FOR i := 1 TO iMax
AADD( aItems, { aStruc[ i ] [ DBS_NAME ], ;
aStruc[ i ] [ DBS_TYPE ], ;
aStruc[ i ] [ DBS_LEN ], ;
aStruc[ i ] [ DBS_DEC ] } )
NEXT
DEFINE WINDOW Form_2 ;
AT 0, 0 ;
WIDTH 330 ;
HEIGHT nHeight + nTitlebar + 40 + 50 ;
TITLE cDbf ;
MAIN ;
ON RELEASE CloseForm2() ;
FONT "Arial" ;
SIZE 11 ;
NOMINIMIZE ;
NOMAXIMIZE ;
NOSIZE
DEFINE TOOLBAR oTOOLBAR BUTTONSIZE 40, 40 FLAT BORDER
BUTTON oBtSave ;
TOOLTIP "F5: create DBF" ;
ACTION SaveCreate()
END TOOLBAR
DEFINE GRID Brow_2
PARENT Form_2
ROW 10 + 50
COL 10
AUTOSIZEWIDTH .T.
AUTOSIZEHEIGHT iMax
HEADERS aCaption
WIDTHS aWide
ITEMS aItems
FONTNAME "Arial"
FONTSIZE 11
VALUE 1
END GRID
END WINDOW
Form_2.height := Form_2.Brow_2.row + Form_2.Brow_2.height + nTitlebar + 2*GetBorderHeight()
Form_2.width := Form_2.Brow_2.col + Form_2.Brow_2.width + 2*GetBorderWidth()
Form_2.Title := (Form_2.Title) + ' -> # visible rows: ' + hb_ntos(GetNumOfVisibleRows('Brow_2', 'Form_2'))
ON KEY F5 OF Form_2 ACTION SaveCreate()
ON KEY ESCAPE OF Form_2 ACTION Form_2.Release
// Form_2.Brow_2.setfocus
CENTER WINDOW Form_2
ACTIVATE WINDOW Form_2
RETURN
Function GetNumOfVisibleRows ( ControlName , ParentForm )
LOCAL i
i := GetControlIndex ( ControlName , ParentForm )
Return ListviewGetCountPerPage ( GetControlHandleByIndex( i ) )
*+--------------------------------------------------------------------
*+
*+ Static Procedure SaveCreate()
*+
*+ Called from ( modistru.prg ) 2 - procedure main()
*+
*+--------------------------------------------------------------------
*+
STATIC PROCEDURE SaveCreate( cOutPutDBF, aNew, aHead, nRowStart, nRowEnd, nColEnd, lDone, aType )
RETURN
*+--------------------------------------------------------------------
*+
*+ Static Procedure CloseForm2()
*+
*+ Called from ( modistru.prg ) 1 - procedure main()
*+
*+--------------------------------------------------------------------
*+
STATIC PROCEDURE CloseForm2()
RETURN
*+ EOF: MODISTRU.PRG
that looks fine, THX