CS-Grid-Gadget: New Release V 2.3 / PB4

Developed or developing a new product in PureBasic? Tell the world about it.
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

Yes.... I know it can be done like that...

But i forgot to mention that the scroll bars should not appear :P has they are not needed most of the time!

And also the locked column shouldn't ever have focus... Only the editable one...
CSAUER
Enthusiast
Enthusiast
Posts: 188
Joined: Mon Oct 18, 2004 7:23 am
Location: Germany

Post by CSAUER »

Use 'CSGridGadget_SetCellLockStatus(test,0,y,-16)' to have no access to the first column. Regarding Scrollbars let me think about to hide them, if they are not required, but then the Image needs to be redefined, but it should be possible (but brings maybe a flicker).
I am thinking about column locking as well.
TerryHough
Enthusiast
Enthusiast
Posts: 781
Joined: Fri Apr 25, 2003 6:51 pm
Location: NC, USA
Contact:

Post by TerryHough »

I have been needing a grid gadget, so took a look at yours. It is
understandable and simple to use.

But, in trying to use the cells, I see that it doesn't always perform as
described. As an example, run the code below:

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
EndIf
Col 1 - defined as a long. Documentation says it would be right justified. It isn't
Col 2 - defined as a float. Again, documentation says it would be right
justified. It isn't. It displays a rounded integer value for the float value
passed to it.
Col 3 - defined as formatted float. Documentation says it will be right
justified with 2 decimal places. And it does just that, but the value
displayed is not rounded properly.
Col 5 - defined as Currency USD. That works, but I couldn't find a way to
change the display format to US style with , (comma) as the thousand
separator and . (decimal) as the decimal place separator.

Every attempt I made to set the user number format resulted in incorrect
numbers displaying. Maybe just me.

You post above mentioned handling for column summarys, but I didn't
find that at all.

Your grid looks really good. A few tweaks and I could be happy with it.
CSAUER
Enthusiast
Enthusiast
Posts: 188
Joined: Mon Oct 18, 2004 7:23 am
Location: Germany

Post by CSAUER »

Thanks to your report. I will fix format-output with next version.
Do you have an idea how can I solve proper rounding without external Lib or API?

Regarding summary: If you have got the latest uploaded version, you may need to use just following command to have a summary:

Code: Select all

CSGridGadget_SetColSummary(test,2,1)                   ; Defines Column-Summary 
If you want to enable col sorting functionality for users, you need to add following commands:

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
If you just only want to resort, use following command:

Code: Select all

CSGridGadget_ColSort(test,3,1)                         ; Sorts the grid according to Column 2 (ascending)
Next version will be bug-fixed and provide some new features and maybe more examples. I plan additionally to pass my lib and sources to PBOSL.
CSAUER
Enthusiast
Enthusiast
Posts: 188
Joined: Mon Oct 18, 2004 7:23 am
Location: Germany

Post by CSAUER »

Uploaded a new version. This version is not looking like it should be, as this is a intermediate release.
I fixed a couple of bugs and extended the column formatting to the requests of TerryHough. Now you should be able to change the comma setting from "," to "." with the new command "CSGridGadget_SetFormatComma(Gadget.l, Char.s)". For US/UK-numberformat it should be used like this:

Code: Select all

CSGridGadget_SetFormatComma(MyCSGridGadget, ".") 
Wrong number-formatting as mentioned by TerryHough should be solved. Correct rounding actually not, as I have no good idea of an easy function for that.

Scrollbars are hidden as long they are not required. Scroll has been improved a little bit.

Finally I added an example how easy you can display SQL-query results with a CSGridGadget.

Next release should add some features.

Regards
CSAUER
TerryHough
Enthusiast
Enthusiast
Posts: 781
Joined: Fri Apr 25, 2003 6:51 pm
Location: NC, USA
Contact:

Post by TerryHough »

Thanks for the update.

Don't know why, even though I had downloaded twice recently, I didn't
have the CSGridGadget_SetColSummary() until todays update. Problem
on my end extracting it I think.

Question 1:
I see how you use CSGridGadget_SetColSummary() to cause a column
to summarize. But, how do you access that total?
CSGridGadget_GetColSummary() appears to return the summary flag,
which is nice to know, but I would like to access the actual summary
amount. Did I overlook something?

Question 2:
Could CSGridGadget_SetColDataType() cause the column to accept only
numerics during entry when the type is set to long integer. Guess that
would be asking too much though given Window's limit on the stringgadget
to 0123456789 and not including the required . (or ,) for real numeric
usage.

Suggetion 1:
Could you create something similar to the
CSGridGadget_SetColUserNumberFormat() for strings? For example,
using something like "###-##-####" to automatically insert the "-" in a
US Social Security Number or "(###) ###-####" for phone numbers.
Now that I write this, I see that my examples are really numbers... hmm.
(Go test a bit)... The currentl CSGridGadget_SetColUserNumberFormat()
almost works. It justs thinks the number is a long and puts a . after it, eg.
a Social Security Number 123-45-6789 appears as 89.-##-####


Maybe these should be defined as "formatted strings"? Here are several
that are in common use here in the US. I will use a N to indicate a number
is expected, an A to indicate a alphabetic character is expected, an X to
indicate an alphanumeric is expected.
Zip Code: NNNNN-NNNN (called Zip+Four)
Social Security Number: NNN-NN-NNNN
Employer ID Number: NN-NNNNNNN
Telehone Number: (NNN) NNN-NNNN or NNN-NNN-NNNN is lesser used
Dates: NN/NN/NNNN indicating MM/DD/YYYY
NN/NN/NN indicating MM/DD/YY is lesser used and
both are alternately shown as NN-NN-NNNN or NN-NN-NN
In even lesser use here in the states is NN AAA, NNNN as in
29 Nov, 2005
I am certain there are similar European formats that are in common use.

Sympathy:
I wish I could help with the rounding problem. I've yet to come up with
a 100% solution. My background is a financial language and I have never
had to deal with such problems there. So, I too am struggling with
proper rounding. Too bad the StrF(Value.f [, NbDecimal]) just truncates
instead of rounding. Perhaps some of the gurus will notice this and
offer a solution.

Thanks for your outstanding efforts
Terry
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

May be you can use StrF(Round(x), ..) ?
CSAUER
Enthusiast
Enthusiast
Posts: 188
Joined: Mon Oct 18, 2004 7:23 am
Location: Germany

Post by CSAUER »

@TerryHough:
Thanks, that are nice suggestions, let me think about and implement some of them, especially the Value of the summary issue.

@Fred:
Thanks for your idea - I never mentioned this command before. It will be maybe a bit harder as I disassemble the value for formatted output, but had no chance to think about in detail.
What do you think about this Gadget?
Sorry, but I didn't had the time to take a look again on Mac-version, if source runs without problems. My first attemp failed and IDE crashed during debugging. I never tested again, but I will do. Do you want to have the sources?
TerryHough
Enthusiast
Enthusiast
Posts: 781
Joined: Fri Apr 25, 2003 6:51 pm
Location: NC, USA
Contact:

Post by TerryHough »

Fred wrote:May be you can use StrF(Round(x), ..) ?
Thanks for the suggestion, Fred. But, I don't get correct results with it.

Round(x,y) doesn't really round, but truncates a float value to the lesser
or greater whole (integer) number depending on the switch.

For example:

Code: Select all

float.f = 123.125456
Result.f = Round(float,1)
MessageRequester("Debug","Rounded value is: " + StrF(Result),0)
returns 124 which certainly isn't the accepted rounded value of the
original number.

IMHO, Round(Number.f, Mode) really should be
Round(Number.f, Number of Decimal Places) and round the value
correctly.

Code: Select all

float.f = 123.125456
Result.f = Round(float,2)
MessageRequester("Debug","Rounded value is: " + StrF(Result),0)
should return 123.13 but I suppose that can't happen due the the float
limitations.

Also, IMHO, the StrF(Value.f [, NbDecimal]) command should be
updated to round the value rather than truncating.

Even this attempt at using the StrF(Round,... fails.

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)
Probably something I don't fully understand, but the intermediate Result of
the Round command shouldn't be 123.12999, should it?

Terry
CSAUER
Enthusiast
Enthusiast
Posts: 188
Joined: Mon Oct 18, 2004 7:23 am
Location: Germany

Post by CSAUER »

You can use CSGridEvent 33 to do any kind of input validation or formatting. You can summarize col totals as well with this way.
But next version will support a command to get value of col sums, if col sum function is enabled.

Regarding rounding: You can step backwards through each digit behind the comma (ending with the last visible digit) and validate if it is greater 5 or not. Maybe I include this function...
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

when doing financial stuff i tend to move away from floats, if possible, and use ints, whilst counting in cents (ie. a virtual comma at two places from the back), i just add the comma when displaying the value
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
CSAUER
Enthusiast
Enthusiast
Posts: 188
Joined: Mon Oct 18, 2004 7:23 am
Location: Germany

Post by CSAUER »

I would like to announce my newest release.
It supports now following new features:
- proper rounding
- checkboxes
- input via textbox, checkbox and drop-down-list
- some tweaks

Here is a screenshot:
Image

Additionally I worked out a row-details function. This means, you can define one object each row for showing addtional details. This objects can be a CSGridGadget as well, so that you can have a list inside a list. Example: You have a main grid with "employees" and you want to show n-qty. of "jobs" each employee is doing.
You can reuse the same gadget each row, if you benefit of the "open details" event to reload the details data.
I kept this undocumented so far, because it has some z-order problems, I cannot solve until now.
Here is a screen to get an idea of the function:
Image

On the displayed test, I just used a StringGadget for test purposes. Normally you would use a Container with multi gadgets or another Grid.

I am open for suggestions, error reports, questions, etc.

Cheers
CSAUER
bender-rulez
User
User
Posts: 49
Joined: Mon Mar 14, 2005 11:30 am

Post by bender-rulez »

Hi,

I just want to test your lib, but could it be that there is no version for linux as promised?


******************************************
PureBasic 3.94 (Linux - x86)
******************************************

Loading external modules...
Starting compilation...
Error: The following PureLibrary is missing: GadgetExtension
CSAUER
Enthusiast
Enthusiast
Posts: 188
Joined: Mon Oct 18, 2004 7:23 am
Location: Germany

Post by CSAUER »

You are right. I am not able to create a UserLib for Mac and Linux. But I can pass the source code, you can include.
It works on MacOSX so far, so I think it would work on Linux as well, because I am using nothing OS specific.

Best Regards
CSAUER
bender-rulez
User
User
Posts: 49
Joined: Mon Mar 14, 2005 11:30 am

Post by bender-rulez »

well, ok! I can test it and if it works I can create the lib for linux!
Post Reply