[Module] GridExModule.pbi

Share your advanced PureBasic knowledge/code with the community.
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

[Module] GridExModule.pbi

Post by Thorsten1867 »

Extended Grid Gadget Module

Extended grid gadget (editable & resize / hide / freeze columns & rows | align / enclose text)
GridExModule is based on MyGrid from' said'. I reworked it and converted it into a module.
  • Various cell types: Normal / Combobox / Checkbox / Button / Image
  • Various cell formats: String / Integer / Float / Money / Date / Time / Grades
  • Cells (Normal / ComboBox) can be edited.
  • Autocomplete for editable cells available
  • Popup menu for Grid
  • Cells with the mouse enlarge/reduce & autobroad width/height at header click
  • Allow or forbid to change the size of the column and row
  • Freeze rows/columns (not scrolled)
  • Sorting row ranges (also in German) & sorting by clicking on column header
  • Multiple sorting possible (e. g. last name, first name)
  • Formatting the different cell formats.
  • Mark(colored) cell contents if they fulfill a condition.
  • Checking the validity of entries for editable cells (e.g. Date, Float, ....)
  • Accept only valid entries for editable cells, if requested
  • Cells with calculations for other cell contents (simple spreadsheet calculation)
  • Export of cell contents as CSV
  • Copy selected cells to/from ClipBoard (CSV or Tabulator)
  • Save/load the changed column/row size and grid size
  • Support of themes for grid design (default & user)
  • Load/Save grid as worksheet (including the used images)
Download: GridExModule.pbi (with example worksheet)
Last edited by Thorsten1867 on Wed Dec 05, 2018 5:01 pm, edited 18 times in total.
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
User avatar
skywalk
Addict
Addict
Posts: 3995
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: [Module] GridExModule.pbi

Post by skywalk »

Really impressive work. 8)
My request is an example that demonstrates copying the contents of a selection of 1 or more rows x columns into the clipboard or just to the debug window as csv text?
And vice versa.
Paste some csv text from the clipboard to a selection of rows x columns.
Thanks.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2058
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: [Module] GridExModule.pbi

Post by Andre »

Like I already wrote in the related topic on German PB forum: very good work, thank you very much! :D

@skywalk: +1 (I would be interested too)
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
loulou2522
Enthusiast
Enthusiast
Posts: 501
Joined: Tue Oct 14, 2014 12:09 pm

Re: [Module] GridExModule.pbi

Post by loulou2522 »

Thanks for this excellent module.
Is-it possible to have autocomplete for a column you choose ?
Have a nice day
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Module] GridExModule.pbi

Post by Thorsten1867 »

Added: GetSelectedCells(GID.i, Array Cells.s(2))

After the original code didn't allow for evaluating selections, I added a command to read the selected cells into an array. (see example 1)
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5353
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: [Module] GridExModule.pbi

Post by Kwai chang caine »

Very very useful code so much missing at PB :|
Thanks a lot at SAID and you for sharing this jewel 8) 8)

Have you planned to resize the columns and rows with mouse, and/or better,.... automatic adjust them with double clic ? :oops:
And image insert in a cell ? :oops:
ImageThe happiness is a road...
Not a destination
User avatar
skywalk
Addict
Addict
Posts: 3995
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: [Module] GridExModule.pbi

Post by skywalk »

Very nice. I added the header row to Cells(). Not sure if you have another method to grab the associated header columns?

Code: Select all

  Procedure   GetSelectedCells(GID.i, Array Cells.s(2))
    Define gid$ = Str(GID)
    Define.i r, c, Row1, Row2, Col1, Col2, idxR=0, idxC=0
    If IsSelected(GID)
      
      Row1 = Grid(gid$)\Row\Current
      Row2 = Grid(gid$)\Block\Row2
      If Row1 > Row2
        Row1 = Grid(gid$)\Block\Row2
        Row2 = Grid(gid$)\Row\Current
      EndIf
      
      Col1 = Grid(gid$)\Col\Current
      Col2 = Grid(gid$)\Block\Col2
      If Col1 > Col2
        Col1 = Grid(gid$)\Block\Col2
        Col2 = Grid(gid$)\Col\Current
      EndIf
      ;//////////////////////////////////////////////////
      ; Prepend Header Row to Cells()
      ;//////////////////////////////////////////////////
      Dim Cells.s(Row2-Row1+1, Col2-Col1)
      r = 0
      idxC = 0 
      For c = Col1 To Col2
        Cells(idxR, idxC) = Grid(gid$)\Col\Label(c)\Value
        idxC + 1
      Next c
      idxR + 1
      ;//////////////////////////////////////////////////
      For r = Row1 To Row2
        idxC = 0 
        For c = Col1 To Col2
          Cells(idxR, idxC) = Grid(gid$)\Rows(r)\Cell(c)\Value
          idxC + 1
        Next c
        idxR + 1
      Next r
    EndIf
    
  EndProcedure  
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Module] GridExModule.pbi

Post by Thorsten1867 »

Updated ...

Code: Select all

  Procedure  GetSelectedCells(GID.i, Array Cells.s(2), HeaderRow=#False)
    Define gid$ = Str(GID)
    Define.i r, c, Row1, Row2, Col1, Col2, idxR=0, idxC=0
    
    If IsSelected(GID)
      
      Row1 = Grid(gid$)\Row\Current
      Row2 = Grid(gid$)\Block\Row2
      If Row1 > Row2
        Row1 = Grid(gid$)\Block\Row2
        Row2 = Grid(gid$)\Row\Current
      EndIf
      
      Col1 = Grid(gid$)\Col\Current
      Col2 = Grid(gid$)\Block\Col2
      If Col1 > Col2
        Col1 = Grid(gid$)\Block\Col2
        Col2 = Grid(gid$)\Col\Current
      EndIf
      
      If HeaderRow
        Dim Cells.s(Row2-Row1+1, Col2-Col1)
        idxC = 0 
        For c = Col1 To Col2
          Cells(idxR, idxC) = Grid(gid$)\Col\Label(c)\Value
          idxC + 1
        Next
        idxR + 1
      Else
        Dim Cells.s(Row2-Row1, Col2-Col1)
      EndIf
      
      For r = Row1 To Row2
        idxC = 0 
        For c = Col1 To Col2
          Cells(idxR, idxC) = Grid(gid$)\Rows(r)\Cell(c)\Value
          idxC + 1
        Next c
        idxR + 1
      Next r
    EndIf
    
  EndProcedure  
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Module] GridExModule.pbi

Post by Thorsten1867 »

Added: AutoComplete for editable cells (list of matching words)
Test it with "Te..." in example 2.

Added: CopyToClipboard(GID.i, Flags.i)
Added: ExportCells() - Export Grid to File (CSV)
Last edited by Thorsten1867 on Fri Nov 10, 2017 3:53 pm, edited 2 times in total.
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
said
Enthusiast
Enthusiast
Posts: 342
Joined: Thu Apr 14, 2011 6:07 pm

Re: [Module] GridExModule.pbi

Post by said »

Nice additions Thorsten1867 :D ... i like your approach to implement the calculations :D

Due to the amount of changes, I wont be able to add most of the new additions ... :shock:
However, looks like few glitches were introduced with your heavy re-work :!: e.g. i am no longer able to resize a row or col, or when i scroll down and then click on a cell the grid scrolls to the top on its own ...

I hope i will be able to upload the latest version of MyGrid within few days (i am adopting it now to 5.61), i had improved some core routines that you can probably make use of in your implementation (by the way since long time now it has the sort implemented, both single or multi columns not rows) ... Good continuation :)

Said
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Module] GridExModule.pbi

Post by Thorsten1867 »

said wrote:However, looks like few glitches were introduced with your heavy re-work :!: e.g. i am no longer able to resize a row or col, or when i scroll down and then click on a cell the grid scrolls to the top on its own .
-> Bugs fixed
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
User avatar
skywalk
Addict
Addict
Posts: 3995
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: [Module] GridExModule.pbi

Post by skywalk »

Box wrote:This shared file or folder link has been removed or is unavailable to you.
Think it's a mistake? No worries: Just email the owner or get in touch with Box support. We're here to help.
:?:
EDIT: download works now...
Last edited by skywalk on Fri Nov 10, 2017 4:17 pm, edited 1 time in total.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
IndigoFuzz

Re: [Module] GridExModule.pbi

Post by IndigoFuzz »

File down :)
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Module] GridExModule.pbi

Post by Thorsten1867 »

Added: Load/Save Grid size & rows height and colums width
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
User avatar
USCode
Addict
Addict
Posts: 912
Joined: Wed Mar 24, 2004 11:04 pm
Location: Seattle, USA

Re: [Module] GridExModule.pbi

Post by USCode »

Is this expected to work on the Mac?
Using PB 5.61 x64, getting an "Invalid memory access" error on line 5603:

Code: Select all

Grid(gid$)\Rows(r)\Height = Size\Rows(r)
Post Reply