cCJGrid with totals << Back



Bob Wosley asked how to relocate/resize the "total" forms in a cCJGrid. Basically Bob wants to create a Form control underneath each cCJGridColumn. When the user resizes any column, the Form control resize with the column. Here is a complete sample. However I do want to note a few things

Use DfAllEnt.pkg
Use ccjGrid.pkg
use ccjGridColumn.pkg

Class cColumnWidthForm is a ccjGridColumn
	Procedure End_Construct_Object
		Handle hForm
		Property Handle phForm
		Forward Send End_Construct_Object
		Get Create of (Parent(Parent(Self))) (RefClass(Form)) to hForm
		Set phForm to hForm
		Set Enabled_State of hForm to False
		Set Value of hForm 0 to (psCaption(Self))
	End_Procedure
	Procedure ResizeForm Integer iColumnX Integer iWidth
		Handle hForm hGrid
		Integer iLoc iSize
		If (IsComObjectCreated(Self)) Begin
			Get phForm to hForm
			If (pbVisible(Self)) Begin
				Set Visible_State of hForm to True
				Get Parent to hGrid
				Get GuiLocation of hGrid to iLoc
				Get GuiSize of hGrid to iSize
				Set GuiLocation of hForm to (Hi(iLoc) + Hi(iSize) + 20) (Low(iLoc) + iColumnX)
				Set GuiSize of hForm to 30 iWidth
				Send Adjust_Logicals of hForm
			End
			Else Set Visible_State of hForm to False
		End
	End_Procedure
End_Class

Class cGridWithForms is a cCJGrid

	Function ColumnVariantToObject Variant llColumn Returns Handle
		Handle hoCol
		Handle[] hColumns
		Integer iColumn
		Get phoColumnObjects to hColumns
        Get phoReportColumn to hoCol
        Set pvComObject of hoCol to llColumn
        Get ComItemIndex of hoCol to iColumn
        Send ReleaseComObject of hoCol
        Function_Return hColumns[iColumn]
	End_Function
	
	Procedure ResizeForms
		Integer iIndex iCount iPosition iWidth
		Handle hColumns hColumn
		Variant vColumn
		Get phoReportColumns to hColumns
		Get ComCount of hColumns to iCount
		Move 0 to iPosition
		Decrement iCount
		For iIndex From 0 to iCount
			Get ComColumn of hColumns iIndex to vColumn
			Get ColumnVariantToObject vColumn to hColumn
			If (Not(IsComObjectCreated(hColumn))) Procedure_Return
			Get ComWidth of hColumn to iWidth
			Send ResizeForm of hColumn iPosition iWidth
			If (pbVisible(hColumn)) Add iWidth to iPosition
		Loop
	End_Procedure
    
	Procedure OnComColumnOrderChangedEx Variant llColumn XTPReportColumnOrderChangedReason llReason
        Forward Send OnComColumnOrderChangedEx llColumn llReason
        Send ResizeForms
    End_Procedure
	
	Procedure OnComColumnWidthChanged Variant llColumn Integer llPrevWidth Integer llNewWidth
		Forward Send OnComColumnWidthChanged llColumn llPrevWidth llNewWidth
		Send ResizeForms
	End_Procedure
	
	Procedure OnCreate
		Forward Send OnCreate
		Send ResizeForms
	End_Procedure
	
End_Class

Object oPanel is a Panel
	Set pbSizeToClientArea to True
	Set Size to 250 300
	Object oGrid is a cGridWithForms
		Set Size to 200 300
		Set peAnchors to anAll
		Object o1 is a cColumnWidthForm
			Set piWidth to 100
			Set psCaption to "Column 1"
		End_Object
		Object o2 is a cColumnWidthForm
			Set piWidth to 50
			Set psCaption to "Column 2"
		End_Object
		Procedure LoadData
	        Handle hoDataSource
	        tDataSourceRow[] TheData
	        Integer iIndex iTotal
	        Get phoDataSource to hoDataSource
	        For iIndex From 0 to 9
	            Move "Column 1" to TheData[iIndex].sValue[0] 
	            Move "Column 2" to TheData[iIndex].sValue[1] 
	        Loop
	        Send InitializeData TheData
	        Send MovetoFirstRow
		End_Procedure
	    Procedure Activating
	        Forward Send Activating
	        Send LoadData
	    End_Procedure
	End_Object
	
End_Object
Start_UI
Free Web Hosting