My MyTable/MyGrid

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
Cyllceaux
Enthusiast
Enthusiast
Posts: 458
Joined: Mon Jun 23, 2014 1:18 pm
Contact:

Re: My MyTable/MyGrid

Post by Cyllceaux »

hey cap...

If I understand you right, you want to do this:

At the moment the "clear all" is the only possibility. Sorry.
V2 has a Paginator for that problem.

The Event for column selection is only in V2, too. I know it is bad to ask... but, can you wait until I finish V2? It is much better than V1.

This change the selected color to green.

Code: Select all

*table\SetSelectedbackground(RGBA(100,200,100,255))
There are 2 Defaults for creating a table/grid:

Code: Select all

#MYTABLE_TABLE_FLAGS_DEFAULT = #MYTABLE_TABLE_FLAGS_GRID|#MYTABLE_TABLE_FLAGS_SORTABLE|#MYTABLE_TABLE_FLAGS_ROW_RESIZEABLE|#MYTABLE_TABLE_FLAGS_COL_RESIZEABLE
#MYTABLE_TABLE_FLAGS_GRID_DEFAULT = #MYTABLE_TABLE_FLAGS_MULTISELECT|#MYTABLE_TABLE_FLAGS_ALL_ROW_COUNT|#MYTABLE_TABLE_FLAGS_EDITABLE|#MYTABLE_TABLE_FLAGS_GRID|#MYTABLE_TABLE_FLAGS_ROW_RESIZEABLE|#MYTABLE_TABLE_FLAGS_COL_RESIZEABLE
if you use #MYTABLE_TABLE_FLAGS_GRID, a grid will be drawn. If you don't use this flag, no grid will be drawing
eck49
Enthusiast
Enthusiast
Posts: 153
Joined: Sat Nov 14, 2020 10:08 pm
Location: England

Re: My MyTable/MyGrid

Post by eck49 »

My next project is one which would make good use of this.
I've downloaded the source (3 June version, from the link in this thread) and got the grid, grid2 and allwithoutgrids examples to execute in the IDE.

I can edit a cell by selecting it and hitting 'Enter' - but the moment I do, the IDE quits, leaving the Table window open and running, so that I can continue to edit the table contents.

Any idea why the IDE quits, and what the effect would be if the Table was just one of a number of gadgets in the window?

(PB5.70 in Ubuntu 16.04)
Ubuntu 22.04 64-bit
Purebasic 6.00 (as of 5 Sep 2022)
(native tongue: English)
eck49
Enthusiast
Enthusiast
Posts: 153
Joined: Sat Nov 14, 2020 10:08 pm
Location: England

Re: My MyTable/MyGrid

Post by eck49 »

I've now downloaded v2 this evening.

The IDE doesn't crash for me now, but with the early test tables (0, 1, 2), I can't edit the tables at all. I've only tried a couple of the others (table16, outlook) but they throw up undeclared variables.....
Ubuntu 22.04 64-bit
Purebasic 6.00 (as of 5 Sep 2022)
(native tongue: English)
Cyllceaux
Enthusiast
Enthusiast
Posts: 458
Joined: Mon Jun 23, 2014 1:18 pm
Contact:

Re: My MyTable/MyGrid

Post by Cyllceaux »

hey eck...

this is strange. Maybe a bug in PB for Linux?


In V2 not all tables/trees of the tests are editable. (Not all of them have the flag #MYTABLE_TABLE_FLAGS_EDITABLE)

I will try this weekend on a linux system. (have to install one first)
User avatar
captain_skank
Enthusiast
Enthusiast
Posts: 636
Joined: Fri Oct 06, 2006 3:57 pm
Location: England

Re: My MyTable/MyGrid

Post by captain_skank »

Cyllceaux wrote: Wed Jun 16, 2021 5:14 pm hey cap...

If I understand you right, you want to do this:

At the moment the "clear all" is the only possibility. Sorry.
V2 has a Paginator for that problem.

The Event for column selection is only in V2, too. I know it is bad to ask... but, can you wait until I finish V2? It is much better than V1.

This change the selected color to green.

Code: Select all

*table\SetSelectedbackground(RGBA(100,200,100,255))
There are 2 Defaults for creating a table/grid:

Code: Select all

#MYTABLE_TABLE_FLAGS_DEFAULT = #MYTABLE_TABLE_FLAGS_GRID|#MYTABLE_TABLE_FLAGS_SORTABLE|#MYTABLE_TABLE_FLAGS_ROW_RESIZEABLE|#MYTABLE_TABLE_FLAGS_COL_RESIZEABLE
#MYTABLE_TABLE_FLAGS_GRID_DEFAULT = #MYTABLE_TABLE_FLAGS_MULTISELECT|#MYTABLE_TABLE_FLAGS_ALL_ROW_COUNT|#MYTABLE_TABLE_FLAGS_EDITABLE|#MYTABLE_TABLE_FLAGS_GRID|#MYTABLE_TABLE_FLAGS_ROW_RESIZEABLE|#MYTABLE_TABLE_FLAGS_COL_RESIZEABLE
if you use #MYTABLE_TABLE_FLAGS_GRID, a grid will be drawn. If you don't use this flag, no grid will be drawing
Hi Cyllceaux - thanks for the info that's helped a lot.

Sure i can wait for V2 - your doing me a favour providing this code not the other way around :D

If i was Kwai chang caine i'd be posting waynes world gifs saying 'were not worthy'.
eck49
Enthusiast
Enthusiast
Posts: 153
Joined: Sat Nov 14, 2020 10:08 pm
Location: England

Re: My MyTable/MyGrid

Post by eck49 »

@cyliceaux

Bear in mind I'm using PB5.70 (5.73 is not compatible with Ubuntu 16.04 and for reasons unrelated to PB I can't upgrade yet).

Thanks for going to all this trouble, far beyond the call of duty. Especially if it turns out I've done something daft.

EDIT 1: Evidence - just from the Table1 example.

The vanilla table1 does not have the EDITABLE flag, so the table is not editable.
1. Adding only that flag causes the gridlines to disappear but I can edit the table. However as soon as I press Enter to do so, the IDE quits, just leaving the app running.
2. Also adding the default flag, so that the call looks like this:

Code: Select all

Global *table.MyTableTable=MyTableCreateTable(window,canvas,vscroll,hscroll, #MYTABLE_TABLE_FLAGS_DEFAULT_TABLE | #MYTABLE_TABLE_FLAGS_EDITABLE)
brings back the gridlines but does not affect the other behaviour.

EDIT 2: More evidence, running with the flag in and inserting a breakpoint.

I double left click in a cell in order to edit it

The breakpoint is 20 lines into MyTable_StartEditCell

on the statement

Code: Select all

*this\edit\window=OpenWindow(#PB_Any,
				                             GadgetX(*this\canvas,#PB_Gadget_ScreenCoordinate)+*cell\startx,
				                             GadgetY(*this\canvas,#PB_Gadget_ScreenCoordinate)+*cell\starty,
				                             *cell\col\calcwidth,
				                             *cell\row\calcheight,
				                             "",
				                             #PB_Window_BorderLess,
				                             GadgetID(*this\canvas))
Executing this statement generates the following (text transcribed not copied so subject to typo)

Code: Select all

WARNING: Invalid cast from GtkLayout to GtkWindow
CRITICAL: gtk_window-set_transient_for:assertion'parent == NULL||GTK_IS_WINDOW(parent)' failed
but if I ignore that I find I can edit the table and close its window successfully.

Without the breakpoint, I can edit the table but the IDE quits.

So either way it looks like I can edit the table, but there is something not quite right about how Ubuntu/PB/this code are interfacing which brings down the IDE if the breakpoint is absent.


EDIT 3: Just to see what would happen, I built an executable out of Table1. It runs with no problems.

This suggests to me it is at root an issue with PB, maybe just with the IDE which ships with 5.70 ?
Perhaps there is a workaround. Any ideas?
Ubuntu 22.04 64-bit
Purebasic 6.00 (as of 5 Sep 2022)
(native tongue: English)
Cyllceaux
Enthusiast
Enthusiast
Posts: 458
Joined: Mon Jun 23, 2014 1:18 pm
Contact:

Re: My MyTable/MyGrid

Post by Cyllceaux »

Hey eck...

At first... I never worked with PB under Linux or Mac... so I have to find out, how this will work... And I'm very curious.

You see, I'm working a lot with flags. I like the idea behind them. The Defaults are mostly the smallest commons. So the later Tests have a BIG flag-line. 8)
eck49 wrote: Thu Jun 17, 2021 4:21 pm

Code: Select all

*this\edit\window=OpenWindow(#PB_Any,
				                             GadgetX(*this\canvas,#PB_Gadget_ScreenCoordinate)+*cell\startx,
				                             GadgetY(*this\canvas,#PB_Gadget_ScreenCoordinate)+*cell\starty,
				                             *cell\col\calcwidth,
				                             *cell\row\calcheight,
				                             "",
				                             #PB_Window_BorderLess,
				                             GadgetID(*this\canvas))
Executing this statement generates the following (text transcribed not copied so subject to typo)

Code: Select all

WARNING: Invalid cast from GtkLayout to GtkWindow
CRITICAL: gtk_window-set_transient_for:assertion'parent == NULL||GTK_IS_WINDOW(parent)' failed
I think I know the Problem. I use the Gadget as the parent. This is "normal" in the windows-world. Maybe the Linux-world has a problem with that. Try this instead:

Code: Select all

*this\edit\window=OpenWindow(#PB_Any,
				                             GadgetX(*this\canvas,#PB_Gadget_ScreenCoordinate)+*cell\startx,
				                             GadgetY(*this\canvas,#PB_Gadget_ScreenCoordinate)+*cell\starty,
				                             *cell\col\calcwidth,
				                             *cell\row\calcheight,
				                             "",
				                             #PB_Window_BorderLess,
				                             WindowID(*this\window))
eck49
Enthusiast
Enthusiast
Posts: 153
Joined: Sat Nov 14, 2020 10:08 pm
Location: England

Re: My MyTable/MyGrid

Post by eck49 »

@Cyliceaux
The change to the window as parent in that statement nailed it. Thanks.

I've not programmed in the Windows world for GUI programming since the days of VB5 and Windows95, and only for my own amusement.

I like your use of flags, especially constants for flags. They serve as a strong reminder of what the line of code is being used for. Well named constants can be as informative as comments, I find.
Ubuntu 22.04 64-bit
Purebasic 6.00 (as of 5 Sep 2022)
(native tongue: English)
Cyllceaux
Enthusiast
Enthusiast
Posts: 458
Joined: Mon Jun 23, 2014 1:18 pm
Contact:

Re: My MyTable/MyGrid

Post by Cyllceaux »

eck49 wrote: Fri Jun 18, 2021 2:23 pm @Cyliceaux
The change to the window as parent in that statement nailed it. Thanks.

I've not programmed in the Windows world for GUI programming since the days of VB5 and Windows95, and only for my own amusement.

I like your use of flags, especially constants for flags. They serve as a strong reminder of what the line of code is being used for. Well named constants can be as informative as comments, I find.
If you have some suggestions for naming (I'm not a native speaker), feel free to tell me :)

Btw... its Cyllceaux, spelled "Silko"
eck49
Enthusiast
Enthusiast
Posts: 153
Joined: Sat Nov 14, 2020 10:08 pm
Location: England

Re: My MyTable/MyGrid

Post by eck49 »

@Cyllceaux
Apologies re name - blame the small font here + perpetual dust on the monitor making lower case I and L look almost identical.

Thanks for the invitation to take part in naming, - I have no suggestions at the moment - you do far better in English than I would in German.

Having done "proof of concept", I now have several days work - maybe longer -to do before using MyTable in earnest. I expect I will have some simple questions at that stage, questions of the "How do I do..." variety.
Ubuntu 22.04 64-bit
Purebasic 6.00 (as of 5 Sep 2022)
(native tongue: English)
Cyllceaux
Enthusiast
Enthusiast
Posts: 458
Joined: Mon Jun 23, 2014 1:18 pm
Contact:

Re: My MyTable/MyGrid

Post by Cyllceaux »

eck49 wrote: Sat Jun 19, 2021 7:58 pm @Cyllceaux
Apologies re name - blame the small font here + perpetual dust on the monitor making lower case I and L look almost identical.

Thanks for the invitation to take part in naming, - I have no suggestions at the moment - you do far better in English than I would in German.

Having done "proof of concept", I now have several days work - maybe longer -to do before using MyTable in earnest. I expect I will have some simple questions at that stage, questions of the "How do I do..." variety.
No problem :)

I create "Creator" which creates code and a preview, so you dont have to always look in the test-codes :)
eck49
Enthusiast
Enthusiast
Posts: 153
Joined: Sat Nov 14, 2020 10:08 pm
Location: England

Re: My MyTable/MyGrid

Post by eck49 »

@Cyllceaux
I've got the beginnings of something working without all the bells and whistles.... (like not enough data validation, for a start!)

I'm in very unfamiliar territory with Interfaces (rather like OO Objects, perhaps?) and Prototypes, so this is probably rather elementary...

1. I select a cell (or row or column) and want to know which one it was, either whether it is the cell in the 7th column and the 39th row, (for example), or perhaps from an id unique to the cell. In an earlier post, in reply to a query about getting the cell (or row etc) data, you put this code:

Code: Select all

Procedure CellSelected(*cell.MyTableCell)
   Protected *row.MyTableRow=*cell\GetRow()

EndProcedure

*table\SetEventCellSelected(@CellSelected())
Would you put a bit of context to this for me, please? I think that the code to act on the cell goes inside the Procedure - the Protected statement for example extracts the row and I guess I can discover which row it is from that. No problem with that.
Is the last line telling MyTable in advance what to do if a cell - any cell - is selected? In which case it can be placed in code just after the table is created or, perhaps more likely, after it is populated.

2. What purpose does the set of procedures with 'Register' in their names serve?

3. In the context of MyTable, what is an Application? It seems to be a choice instead of a grid or a table.

4. Resizing when the Table does not occupy the whole window. I think the choices when resizing are (a) resize the canvas (b) resize the Table (c) resize each column (or just some of them) (d) resize each row (or just some of them). These do different things, of course, and can be used in conjunction, but does that cover every option? All but the first are calls to MyTable routines.

I see there is a new v2, but I'm still using the June16 code at present - one thing at a time! I need calm water before updating.
Ubuntu 22.04 64-bit
Purebasic 6.00 (as of 5 Sep 2022)
(native tongue: English)
Cyllceaux
Enthusiast
Enthusiast
Posts: 458
Joined: Mon Jun 23, 2014 1:18 pm
Contact:

Re: My MyTable/MyGrid

Post by Cyllceaux »

Hey eck...
  1. Every Row and Col knows his position in the table/grid. I distinguish between the data table and the visible table. For example a simple tree. If you collapse a tree-node, the children aren't visible anymore. So they habe no position in the visible table. If you use *row\GetPosition(), it gives you the Position in the visible table. The same for *col\GetPosition()

    But, if you say *table\GetRow(row.) or *row\GetRow(row.), it will give you the data row. The Table does not know anything about the children of his children. Sounds hard, but it was a design and performance decision.

    So... to know the row position and col position of the visible table, your code is right.

    Code: Select all

    Procedure CellSelected(*cell.MyTableCell)
       Protected *row.MyTableRow=*cell\GetRow()
       Protected *col.MyTableCol=*cell\GetCol()
    
       Debug "Data: "+*row\GetPosition()+"/"+*col\GetPosition()
       Debug "Visible "+*row\GetVisiblePosition()+"/"+*col\GetPosition()
    EndProcedure
    
  2. I'm not sure... But in one code example, the developer "registered" callbacks and events. So I took this wording. But I can rename it to "Bind" Maybe it is better to understand
  3. This is for sharing styles and tables. Yes... If you have a formula with a relation to another table, the tables have to know each others. so the "application" is the group object. I will use it for load and save for Excel and Calc, too. Btw. The root Element in Excel and Calc called application, too. :) (followed by Workbook, Worksheet... and so on)
  4. if you want to resize the table, just resize the canvas. The table will redraw :) And you can set the RESIZE Flag on each element. so you can control, if you only want to resize a special cell, row, column or everything. RESIZE in this context means, resizing with the mouse.
At the moment I'm talking in V2... I changed a lot in this version. Things I did architecturally wrong in V1.
eck49
Enthusiast
Enthusiast
Posts: 153
Joined: Sat Nov 14, 2020 10:08 pm
Location: England

Re: My MyTable/MyGrid

Post by eck49 »

Hi Cyllceaux

Thanks for your explanations.

This post has been radically edited, by which I mean completely rewritten.

I originally was asking how to code the missing link which would tell the user's CellSelected routine which cells had been selected and how to find out what was in the cells, but have managed to find a solution myself. After some experimentation, this is how it can be done using a conventional event loop, documented here mainly for my own benefit. This is based on table1 example, modified so the canvas does not fill the window (to show irrelevant events are not captured). My added code is within vv ^^. This code is not elegant as it stands, but it works. I used your code version 3228 of 24 June 2021 here.

I note that the IDE (at least the 5.70 IDE) is not very helpful over syntax errors and identifying errors with Interface calls. It will say there is an error but not say where in the statement it found it. Which leaves a lot of scope for investigation! Nonetheless, PB is impressive, and the MyTable code is impressive. Cyllceaux, I salute you!

Code: Select all

EnableExplicit

XIncludeFile "mytable.pbi"   ;added
XIncludeFile "mytablestructures.pb" ;added
XIncludeFile "declare.pb"

UseModule MyTable
	
	Global window=OpenWindow(#PB_Any,0,0,800,600,"Table1",#PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_SizeGadget|#PB_Window_MaximizeGadget|#PB_Window_MinimizeGadget)
	Global canvas=CanvasGadget(#PB_Any,50,50,WindowWidth(window)-100,WindowHeight(window)-100,#PB_Canvas_Container|#PB_Canvas_Keyboard)
	Global hscroll=ScrollBarGadget(#PB_Any,0,0,0,20,0,0,0)
	Global vscroll=ScrollBarGadget(#PB_Any,0,0,20,0,0,0,0,#PB_ScrollBar_Vertical)
	CloseGadgetList()
	
	Global *table.MyTableTable=MyTableCreateTable(window,canvas,vscroll,hscroll)
	*table\SetRedraw(#False)
	*table\SetHeaderHeight(40)
	Define *col.MyTableCol,*style.MyTableStyle
	*col=*table\AddCol("Test 1",100):*style=*col\GetDefaultStyle():*style\SetHAlign(#MYTABLE_STYLE_HALIGN_LEFT)
	*col=*table\AddCol("Test 2",100):*style=*col\GetDefaultStyle():*style\SetHAlign(#MYTABLE_STYLE_HALIGN_CENTER)
	*col=*table\AddCol("Test 3",100):*style=*col\GetDefaultStyle():*style\SetHAlign(#MYTABLE_STYLE_HALIGN_RIGHT)
	*col=*table\AddCol("Test 4",100):*style=*col\GetDefaultStyle():*style\SetHAlign(#MYTABLE_STYLE_HALIGN_LEFT):*style\SetVAlign(#MYTABLE_STYLE_VALIGN_TOP)
	*col=*table\AddCol("Test 5",100):*style=*col\GetDefaultStyle():*style\SetHAlign(#MYTABLE_STYLE_HALIGN_CENTER):*style\SetVAlign(#MYTABLE_STYLE_VALIGN_MIDDLE)
	*col=*table\AddCol("Test 6",100):*style=*col\GetDefaultStyle():*style\SetHAlign(#MYTABLE_STYLE_HALIGN_RIGHT):*style\SetVAlign(#MYTABLE_STYLE_VALIGN_BOTTOM)
	
	
	#Rows=100
	#Cols=10
	
	Define i,g
	For g=7 To #Cols
		*table\AddCol("Test "+g,100)
	Next
	For i=1 To #Rows
		Define line.s="Test 1_"+i
		For g=2 To #Cols
			line+"|Test "+g+"_"+i
		Next
		*table\AddRow(line)
	Next
	
	*table\SetRedraw(#True)
	
	Procedure Resize()
		ResizeGadget(canvas,
		             #PB_Ignore,
		             #PB_Ignore,
		             WindowWidth(window),
		             WindowHeight(window))
	EndProcedure
	
	;vv
	Procedure CellSelected(*cell.MyTableCell)
   Protected *row.MyTableRow=*cell\GetRow()
   Protected *col.MyTableCol=*cell\GetCol()
   Protected.s st = *cell\GetText()
   
   Debug ""+*row\GetPosition()+"  "+*col\GetPosition() + "  "+ st
EndProcedure
	;^^
	
	BindEvent(#PB_Event_SizeWindow,@Resize(),window)
	BindEvent(#PB_Event_RestoreWindow,@Resize(),window)
	BindEvent(#PB_Event_MaximizeWindow,@Resize(),window)
	BindEvent(#PB_Event_MinimizeWindow,@Resize(),window)
	
	;Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
	;vv
	Repeat
	  Select WaitWindowEvent()
    Case #PB_Event_Gadget
      Define mEventType = EventType()
      Select EventGadget()
          
        Case canvas
            If mEventType = #PB_EventType_LeftDoubleClick
              Define NewList *cellX.MyTableCell()
              *table\GetSelectedCells(*cellX())
              ForEach *cellX()
                CellSelected(*cellX())
              Next  
          EndIf  
      EndSelect    
	  EndSelect
	Until WaitWindowEvent()=#PB_Event_CloseWindow
 ;^^	
	*table\Free()
UnuseModule MyTable
Ubuntu 22.04 64-bit
Purebasic 6.00 (as of 5 Sep 2022)
(native tongue: English)
Cyllceaux
Enthusiast
Enthusiast
Posts: 458
Joined: Mon Jun 23, 2014 1:18 pm
Contact:

Re: My MyTable/MyGrid

Post by Cyllceaux »

Hey eck...

You think to complicated... it is much easier.

Code: Select all

EnableExplicit

XIncludeFile "mytable.pbi"   ;The only include you need

UseModule MyTable
	
	Global window=OpenWindow(#PB_Any,0,0,800,600,"Table1",#PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_SizeGadget|#PB_Window_MaximizeGadget|#PB_Window_MinimizeGadget)
	Global canvas=CanvasGadget(#PB_Any,50,50,WindowWidth(window)-100,WindowHeight(window)-100,#PB_Canvas_Container|#PB_Canvas_Keyboard)
	Global hscroll=ScrollBarGadget(#PB_Any,0,0,0,20,0,0,0)
	Global vscroll=ScrollBarGadget(#PB_Any,0,0,20,0,0,0,0,#PB_ScrollBar_Vertical)
	CloseGadgetList()
	
	Global btn=ButtonGadget(#PB_Any,10,10,150,22,"Show selected Cells")
	
	; I changed to Multiselect
	Global *table.MyTableTable=MyTableCreateTable(window,canvas,vscroll,hscroll,#MYTABLE_TABLE_FLAGS_DEFAULT_TABLE|#MYTABLE_TABLE_FLAGS_MULTISELECT)
	*table\SetRedraw(#False)
	*table\SetHeaderHeight(40)
	Define *col.MyTableCol,*style.MyTableStyle
	*col=*table\AddCol("Test 1",100):*style=*col\GetDefaultStyle():*style\SetHAlign(#MYTABLE_STYLE_HALIGN_LEFT)
	*col=*table\AddCol("Test 2",100):*style=*col\GetDefaultStyle():*style\SetHAlign(#MYTABLE_STYLE_HALIGN_CENTER)
	*col=*table\AddCol("Test 3",100):*style=*col\GetDefaultStyle():*style\SetHAlign(#MYTABLE_STYLE_HALIGN_RIGHT)
	*col=*table\AddCol("Test 4",100):*style=*col\GetDefaultStyle():*style\SetHAlign(#MYTABLE_STYLE_HALIGN_LEFT):*style\SetVAlign(#MYTABLE_STYLE_VALIGN_TOP)
	*col=*table\AddCol("Test 5",100):*style=*col\GetDefaultStyle():*style\SetHAlign(#MYTABLE_STYLE_HALIGN_CENTER):*style\SetVAlign(#MYTABLE_STYLE_VALIGN_MIDDLE)
	*col=*table\AddCol("Test 6",100):*style=*col\GetDefaultStyle():*style\SetHAlign(#MYTABLE_STYLE_HALIGN_RIGHT):*style\SetVAlign(#MYTABLE_STYLE_VALIGN_BOTTOM)
	
	
	#Rows=100
	#Cols=10
	
	Define i,g
	For g=7 To #Cols
		*table\AddCol("Test "+g,100)
	Next
	For i=1 To #Rows
		Define line.s="Test 1_"+i
		For g=2 To #Cols
			line+"|Test "+g+"_"+i
		Next
		*table\AddRow(line)
	Next
	
	*table\SetRedraw(#True)
	
	
	Procedure Resize()
		; I changed it a little
		ResizeGadget(canvas,
		             #PB_Ignore,
		             #PB_Ignore,
		             WindowWidth(window)-100,
		             WindowHeight(window)-100)
	EndProcedure
	
	;vv
	;Triggered every time you select a cell
	Procedure CellSelected(*cell.MyTableCell)
		Protected *row.MyTableRow=*cell\GetRow()
		Protected *col.MyTableCol=*cell\GetCol()
		Protected.s st = *cell\GetText()
		
		Debug ""+*row\GetPosition()+"  "+*col\GetPosition() + "  "+ st
	EndProcedure
	;^^
	
	;Triggert by pressing the button
	Procedure showCells()
		Protected NewList cells.MyTableCell()
		*table\GetSelectedCells(cells())
		
		ForEach cells()
			; Not nice... But workes
			CellSelected(cells())
		Next
		
		FreeList(cells())
	EndProcedure
	BindGadgetEvent(btn,@showCells())
	
	; This is what you want
	;*table\BindEventCellSelected(@CellSelected()) ;actual V2 >3300
	*table\RegisterEventCellSelected(@CellSelected()); V2 <3300
	
	BindEvent(#PB_Event_SizeWindow,@Resize(),window)
	BindEvent(#PB_Event_RestoreWindow,@Resize(),window)
	BindEvent(#PB_Event_MaximizeWindow,@Resize(),window)
	BindEvent(#PB_Event_MinimizeWindow,@Resize(),window)
	
	;vv
	Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
	;^^	
	*table\Free()
UnuseModule MyTable
I changed to "Multiselect", so the button on left top makes more sense :)

The *table\GetSelectedCells() gives you the selected cells every time you want. not only in events.

I tested it in PB570 and in my Version 3228.

oh... and I fixed a bug... what occurs in your example... some event was not triggered in multiselect :oops:
Post Reply