But i forgot to mention that the scroll bars should not appear
And also the locked column shouldn't ever have focus... Only the editable one...

Code: Select all
; ************************************************************************
; ** DEMO CS-GRID V1.03 *** (c) 2005 Christian Walde-Sauer, 27.10.2005 ***
; ************************************************************************
; * Last Edit 07.11.2005                                                 *
; * Demo-Routing for multiple Edit-Grid-Gadgets with easy implementation *
; ************************************************************************
; Additional information:
; - Contains no special Windows library commands, should be runable for windows/linux/macosx - actually no chance to test
; - Supports nearly all native Gadget commands
; - Multiple customizing commands (colors, designs, etc.)
; - Free to be used for own projects (mentioned in credits would be welcome), delivered as it is
; - Future plans:
;   - Datainput by selection out of a list (source based on a SQL string with two columns)
;   - Column-Sorting 
;   - Embedded sub-container for detailed information
wStyle = #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered
hWnd = OpenWindow(0, 0, 0, 800, 400, wStyle, "Terry's CS-Grid-Gadget")
If hWnd 
  CreateGadgetList(WindowID())
  
  test = CSGridGadget(#PB_Any,10,10,743,300,10,5) ; Creates a CS-Grid-Gadget
  CSGridGadget_SetAutoRedraw(test,-1)             ; Turns off Auto-Redraw for Grid 1 for faster setup
  CSGridGadget_SetColCaptionVisibility(test,1)    ; Shows a column header (default empty caption)
  CSGridGadget_SetColCaption(test,0,"String")     ; Defines custom header Labels for all Columns
  CSGridGadget_SetColCaption(test,1,"Long")       ; Defines custom header Labels for all Columns
  CSGridGadget_SetColCaption(test,2,"Float")      ; Defines custom header Labels for all Columns
  CSGridGadget_SetColCaption(test,3,"Formatted")  ; Defines custom header Labels for all Columns
  CSGridGadget_SetColCaption(test,4,"Percentage") ; Defines custom header Labels for all Columns
  CSGridGadget_SetColCaption(test,5,"US Dollars") ; Defines custom header Labels for all Columns
  CSGridGadget_SetColCaption(test,6,"User Fmt")   ; Defines custom header Labels for all Columns
  CSGridGadget_SetRowCaptionVisibility(test,1)    ; Shows a row header (default numbered caption)
  CSGridGadget_SetColWidth(test,2,100)            ; Defines Column-Width for Column 2
  CSGridGadget_SetColWidth(test,3,100)            ; Defines Column-Width for Column 3
  CSGridGadget_SetColWidth(test,5,100)            ; Defines Column-Width for Column 5
  CSGridGadget_SetColWidth(test,6,100)            ; Defines Column-Width for Column 6
  CSGridGadget_SetColDataType(test,0,0)           ; Defines Output-Type to Text for Column 0
  CSGridGadget_SetCellValue(test,0,0,"TESTING")   ; Defines new Content for Cell C:0 R:0  
  
  CSGridGadget_SetColDataType(test,1,1)           ; Defines Output-Type to Long Integer for Column 1
  CSGridGadget_SetCellValue(test,1,0,"654924")    ; Defines new Content for Cell C:1 R:0  
  
  CSGridGadget_SetColDataType(test,2,16)          ; Defines Output-Type to Float for Column 2
  CSGridGadget_SetCellValue(test,2,0,"139.6548")  ; Defines new Content for Cell C:2 R:0  
  CSGridGadget_SetColDataType(test,3,17)          ; Defines Output-Type to Formatted Fload, 2 decimals places
;  CSGridGadget_SetColUserNumberFormat(test,3,"##,###,###.00") ; Defines User-Output-Type for Column 3
  CSGridGadget_SetCellValue(test,3,0,"1221.105")   ; Defines new Content for Cell C:3 R:0  
  
  CSGridGadget_SetColDataType(test,4,64)          ; Defines Output-Type to Percentage, 4 decimals places
  CSGridGadget_SetCellValue(test,4,0,"0.456789")  ; Defines new Content for Cell C:3 R:0  
  CSGridGadget_SetColDataType(test,5,33)          ; Defines Output-Type to US Dollars, 2 decimals places
  CSGridGadget_SetColUserNumberFormat(test,5,"#######0.00") ; Defines User-Output-Type for Column 3
  CSGridGadget_SetCellValue(test,5,0,"150286")  ; Defines new Content for Cell C:3 R:0  
  CSGridGadget_SetColDataType(test,6,127)          ; User defined Output-Type
  ;CSGridGadget_SetColUserNumberFormat(test,6,"#######0.00") ; Defines User-Output-Type for Column 3
  CSGridGadget_SetCellValue(test,6,0,"1502.86")  ; Defines new Content for Cell C:3 R:0  
  CSGridGadget_SetCellValue(test,2,1,"No Access") ; Defines new Content for Cell C:2 R:1
  
  CSGridGadget_SetCellLockStatus(test,2,2,-16)    ; Locks Cell C:2 R:2 for access (and input)
  CSGridGadget_SetCellValue(test,3,3,"No Edit")   ; Defines new Content for Cell C:3 R:3
  CSGridGadget_SetCellLockStatus(test,3,3,-1)     ; Locks Cell C:3 R:3 for input
  
  CSGridGadget_SetAutoRedraw(test,1)              ; Turns on Auto-Redraw for Grid 1 for faster setup
  
  Repeat 
      main_EventID = WaitWindowEvent()
      Select main_EventID
        Case #PB_Event_SizeWindow
          CSGridGadget_Resize(test,10,10,743,300) ; Resizes Grid 1
        Default
          CSGridGadget_EventHandling(main_EventID); Processes all Grid-Gadget events (for all CS-Grid-Gadgets)
      EndSelect
  Until main_EventID = #PB_Event_CloseWindow
  CSGridGadget_FreeGadget(test)                   ; Removes the Grid with all sub-objects and frees memor, alternatively native command: RemoveGadget
  End
EndIfCode: Select all
CSGridGadget_SetColSummary(test,2,1)                   ; Defines Column-Summary Code: Select all
CSGridGadget_SetAutoSort(test,1)                       ; Activates autom. sorting acc. last sorting criteria (if new row added or content changed)
CSGridGadget_SetColsUserSort(test,1)                   ; Activates user sorting via double-click on column headder
Code: Select all
CSGridGadget_ColSort(test,3,1)                         ; Sorts the grid according to Column 2 (ascending)Code: Select all
CSGridGadget_SetFormatComma(MyCSGridGadget, ".") 

Thanks for the suggestion, Fred. But, I don't get correct results with it.Fred wrote:May be you can use StrF(Round(x), ..) ?
Code: Select all
float.f = 123.125456
Result.f = Round(float,1)
MessageRequester("Debug","Rounded value is: " + StrF(Result),0)
Code: Select all
float.f = 123.125456
Result.f = Round(float,2)
MessageRequester("Debug","Rounded value is: " + StrF(Result),0)
Code: Select all
float.f = 123.123456
DecPlaces = 2
Result.f = Round(float * Pow(10, DecPlaces),1)/Pow(10,DecPlaces)
MessageRequester("Rounding","Round(x,y) value was: " + StrF(Result) + #LF$ + "Rounded value is: " + StrF(Result,2) + #LF$ + "Incorrect rounding to 2 places",0)



