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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
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