#include "minigui.ch" #include "tsbrowse.ch" Function SBArray() Local oDlg, bData, bcolor, bAlign, bDelete, aBmp[ 2 ], Arr1, ; nTot2, nTot3, oFont, nGood, nBad, nPreVal, aColor[ 2 ] Arr1 := {} Private oLbx AADD( Arr1, {"Ena ", 100, 200} ) AADD( Arr1, {"Dyo ", 125, 200} ) AADD( Arr1, {"Dekaepta ", 100, 300} ) AADD( Arr1, {"Dekaokto ", 100, 200} ) nTot2 := nTot3 := nGood := nBad := nPreVal := 0 // footers values at start AEval( Arr1, { | e | nTot2 += e[ 2 ], nTot3 += e[ 3 ], ; If( ( e[ 2 ] + e[ 3 ] ) < 325, ++nGood, ++nBad ) } ) aBmp:= { LoadIcon( "Level1.bmp" ), ; LoadIcon( "Level2.bmp" )} DEFINE WINDOW Form_3 ; AT 100,50 ; WIDTH 500 HEIGHT 400 ; TITLE "MiniGUI TsBrowse ( Browsing an array ) " ; FONT "MS Sans Serif" SIZE 8 ; MAIN @ 320, 20 Label Label_1 Value "" Width 100 Define Statusbar StatusItem "" End statusbar DEFINE TBROWSE oLbx AT 10,15 ; OF Form_3 WIDTH 470 HEIGHT 290 CELLED; COLORS {CLR_BLACK, CLR_CYAN} ; On Change Show( oLbx ) oLbx:SetArray( Arr1 ) // this is necessary to work with arrays // let's define the block for background color bColor := { || If( oLbx:nAt % 2 == 0, CLR_YELLOW, CLR_CYAN ) } ADD COLUMN TO TBROWSE oLbx DATA ARRAY ELEMENT 1; TITLE "Col 1" ; SIZE 120 EDITABLE; // this column is editable COLORS CLR_BLACK, bColor; // background color from a Code Block 3DLOOK TRUE, TRUE, TRUE; // cells, titles, footers MOVE DT_MOVE_NEXT; // cursor goes to next editable column VALID { | uVar | ! Empty( uVar ) }; // don't want empty rows ALIGN DT_LEFT, DT_CENTER, DT_RIGHT; // cells, title, footer FOOTER "Totals->" ADD COLUMN TO TBROWSE oLbx DATA ARRAY ELEMENT 2; TITLE "Col 2" ; ALIGN DT_RIGHT, DT_CENTER; // let's align cells to right and center title SIZE 80 EDITABLE; // this column is editable COLORS CLR_BLACK, bColor; // background color from a Code Block 3DLOOK TRUE, TRUE, TRUE; // cells, titles, footers MOVE DT_MOVE_NEXT; // cursor goes to next editable column FOOTER { || Transform( nTot2, "##,###" ) }; // must be a code block PREEDIT { | uVar | nPreVal := uVar }; // updating footer value POSTEDIT { | uVar | nTot2 += ( uVar - nPreval ), ; If( Eval( oLbx:aColumns[ 4 ]:bData ) < 325, ; If( oLbx:lChanged, ( ++nGood, --nBad ), Nil ), ; If( oLbx:lChanged, ( ++nBad, --nGood ), Nil ) ), ; oLbx:DrawFooters() } ADD COLUMN TO TBROWSE oLbx DATA ARRAY ELEMENT 3; TITLE "Col 3" ; ALIGN DT_RIGHT, DT_CENTER; // let's align cells to right and center title SIZE 80 EDITABLE; // this column is editable COLORS CLR_BLACK, bColor; // background color from a Code Block 3DLOOK TRUE, TRUE, TRUE; // cells, titles, footers MOVE DT_MOVE_NEXT; // cursor goes to next editable column FOOTER { || Transform( nTot3, "##,###" ) }; // must be a code block PREEDIT { | uVar | nPreVal := uVar }; // updating footer value POSTEDIT { | uVar | nTot3 += ( uVar - nPreval ), ; If( Eval( oLbx:aColumns[ 4 ]:bData ) < 325, ; If( oLbx:lChanged, ( ++nGood, --nBad ), Nil ), ; If( oLbx:lChanged, ( ++nBad, --nGood ), Nil ) ), ; oLbx:DrawFooters() } // next column is not part of the array, then bData must be defined apart bData := { || If( ! oLbx:lAppendMode, ; oLbx:aArray[ oLbx:nAt, 2 ] + ; oLbx:aArray[ oLbx:nAt, 3 ], 0 ) } // dynamic setting of background color for next column depending on cell's value bColor := { || If( Eval( oLbx:aColumns[ 4 ]:bData ) < 325, CLR_RED, CLR_CYAN ) } ADD COLUMN TO TBROWSE oLbx DATA bData; TITLE "Col 4" ; ALIGN DT_RIGHT, DT_CENTER; // let's align cells to right and center title SIZE 80; // this column is NOT editable COLORS CLR_WHITE, bColor; // background color from a Code Block 3DLOOK TRUE, TRUE, TRUE; // cells, titles, footers FOOTER { || Transform( nTot2 + nTot3, "##,###" ) } // with next column let's try BitMaps on cells with dynamic alignment bData := { || If( Eval( oLbx:aColumns[ 4 ]:bData ) < 325, ; aBmp[ 1 ], aBmp[ 2 ] ) } // new V.7.0 merging data and bitmaps at specific cell position // a value greater than 4 in HiWord, means specific pixel location from column left bAlign := { || nMakeLong( DT_LEFT, ; // LoWord = data alignment If( Eval( oLbx:aColumns[ 4 ]:bData ) < 325, ; 10, 50 ) ) } // HiWord = bitmap alignment ADD COLUMN TO TBROWSE oLbx DATA bData ; BITMAP; // tells TSBrowse that data is a BitMap TITLE "Result" + CRLF + "Good Bad"; // Multi-Line heading ALIGN bAlign, DT_CENTER, DT_CENTER; // cell, title, footer SIZE 71; // this column is NOT editable 3DLOOK TRUE, TRUE, TRUE; // cells, titles, footers FOOTER { || Str( nGood, 4 ) + " Good" + CRLF + ; Str( nBad, 4 ) + " Bad" } // Multi-Line footer // activating Auto Append Mode oLbx:SetAppendMode( .T. ) // activating Auto Delete Mode // I'll use bDelete code block to update footers bDelete := { | nAt, oBrw | nTot2 -= oBrw:aArray[ nAt, 2 ], ; nTot3 -= oBrw:aArray[ nAt, 3 ], ; If( ( oBrw:aArray[ nAt, 2 ] + ; oBrw:aArray[ nAt, 3 ] ) < 325, ; --nGood, --nBad ), oBrw:DrawFooters() } oLbx:SetDeleteMode( .T., .T., bDelete ) // ( lOnOff, lConfirm, bDelete ) // Assigning default values to new elements created with Auto Append. // For last column (5), I'm using a code block to update footers without // assigning any value to that column, since code block returns Nil oLbx:aDefault := { Nil, 50, 50, Nil, ; { || nTot2 += 50, nTot3 += 50, ++nGood, ; oLbx:DrawFooters(), Nil } } // using Super Titles ADD SUPER HEADER TO oLbx FROM COLUMN 2 TO COLUMN 3 ; TITLE "Col2 and Col 3" 3DLOOK // increasing cell and super header height oLbx:nHeightCell += 2 oLbx:nHeightSuper += 7 END TBROWSE END WINDOW ACTIVATE WINDOW Form_3 Return Nil Static Procedure Show Memvar oLbx Local cVal := oLbx:aArray[ oLbx:nAt , 1 ] Form_3.StatusBar.Item(1) := cVal Form_3.Label_1.Value := cVal Return
|