Inserting a table in a tabel cell

Post your Gambas programming questions here.
Post Reply
seany
Posts: 32
Joined: Friday 6th December 2019 3:09pm

Inserting a table in a tabel cell

Post by seany »

Hi

I am creating an interface to manage my AI training data. I wanted to rapidly prototype it with gambas, version 3.17.5.

I need a tabular display, where I can add / insert subtables in a table cell. That way I want to be able to display some combinatorial graphs connecting various parameters.

Looking at the wiki, I can't find anything. Any help will be appreciated
User avatar
BruceSteers
Posts: 1523
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Inserting a table in a tabel cell

Post by BruceSteers »

Can the cells .Tag property help?
As type variant it can be anything. Then the visible data can be a string representation.

Failing that make an array like TableData As Variant[][]
that could easily be made to hold data relevant to the current cell at column/row.


Have you tried making a new table with the current cell as it's parent?
If at first you don't succeed , try doing something differently.
BruceS
seany
Posts: 32
Joined: Friday 6th December 2019 3:09pm

Re: Inserting a table in a tabel cell

Post by seany »

Hi

Thank you for the reply.

Consider this code snippet, please.
Public Sub Button2_Click()

  
  
  Dim newTable As New TableView(parentTable.Current) As "Dyntable" 'consider this line especially
  Print "new table is being created"
  Print parentTable.Tag
  
  Dim code As String = ""
  Dim i, j As Integer
  
  For i = 1 To 2
    For j = 1 To 4
      Dim c As String = Chr(Rand(48, 57))
      code = code & c
    Next
    code = code & "-"
  Next
  
  code = code[0, Len(code) - 1]
  
  newTable.Columns.Count = 3
  newTable.Columns[0].Title = "Variable Class (subtable)"
  newTable.Columns[0].Width = newTable.Font.TextWidth(newTable.Columns[0].Title) + 10
  newTable.Columns[1].Text = "ID"
  newTable.Columns[1].Width = newTable.Font.TextWidth(newTable.Columns[1].Title) + 100
  newTable.Columns[2].Text = "DATA"
  newTable.Columns[2].Width = newTable.Font.TextWidth(newTable.Columns[2].Title) + 200
  
  'newTable.Rows.Count = newTable.Rows.Count + 1
  
  newTable.Width = mainArea.Width + 10
  newTable.Height = mainArea.Height - newTable.Top - 5 - 10
  newTable.Resizable = True
  newTable.Header = newTable.Horizontal
  
  newTable.Tag = code
  
  newTable.Resizable = True
  

End
Beyond that --> consider the image please.

Image

Initially, parentTable is set as the form itself. Then I create a new row in the grid view that is visible, by clicking "Create root". I select a cell where i want to insert the subtable, and then click "create leaf". The clicking action sets the available gridview as parent table.

The error is "Type conflict: Expected container, found _Gridview_Cell". So the container plan does not really work

But I will try to work the rest out using tags.
User avatar
BruceSteers
Posts: 1523
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Inserting a table in a tabel cell

Post by BruceSteers »

Yes i think a gridview and each cell is more a drawn area in one big outer container and not a bunch of smaller containers that objects can be added to.
If at first you don't succeed , try doing something differently.
BruceS
seany
Posts: 32
Joined: Friday 6th December 2019 3:09pm

Re: Inserting a table in a tabel cell

Post by seany »

same thing happens with a table view as well
User avatar
BruceSteers
Posts: 1523
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Inserting a table in a tabel cell

Post by BruceSteers »

seany wrote: Thursday 20th October 2022 3:47pm same thing happens with a table view as well
Yes a TableView inherits GridView https://gitlab.com/gambas/gambas/-/blob ... View.class

it's essentially just a GridView with added cell editing abilities so apart from the editing it behaves exactly the same as a GridView will.

You could possibly get what you want just by using a ScrollView Arranged Vertically
Then adding Panels containing your TableViews and other data

probably just easiest to use a multi-line string representation and make a popup window to edit if needed
there's always a way :)
If at first you don't succeed , try doing something differently.
BruceS
seany
Posts: 32
Joined: Friday 6th December 2019 3:09pm

Re: Inserting a table in a tabel cell

Post by seany »

Hi


So the process continues. I can overlay tables on top of each other, I am still refining the process. Please see image.

Image

The table marked with green arrow is the outermost "master". It can be seen that the subtable is marked in red arrow, is well placed in the cell. Ignore the other tables please.

Now, if i click on the cell marked with the blue triangle, sometimes it returns that the

Code: Select all

Last
object is the outermost table (which is not correct) and sometimes, it is indeed the subtable marked in red (which is correct, the use of red and green as color markers are not related to correctness. That was arbitrary). Clicking on the column headers results in the same.

How can I ensure to place a particular object at a particular Z index, and ensure that clicking on one editable object will not go through it, activating the object underneath it?

Thank you.
User avatar
BruceSteers
Posts: 1523
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Inserting a table in a tabel cell

Post by BruceSteers »

I think you should veer away from the initial object being a TableView

Attached is a simple example of using a scrollview and manually adding panels. I just added a TableView and a VBox with a delete button in it.

But you are free to add whatever you like as normal to each newly added panel. no TableView/GridView restrictions.

the code is just this...
' Gambas class file

Public Sub Form_Open()

  ScrollView1.Spacing = True
  ScrollView1.Padding = 2
  ScrollView1.Arrangement = Arrange.Vertical

End

Public Sub btnadd_Click()

  Dim iCount As Integer = ScrollView1.Children.Count

  Dim h As Panel = New Panel(ScrollView1)  ' make a panel

  h.Width = ScrollView1.Width
  h.Arrangement = Arrange.Horizontal

  Dim tv As TableView
  With tv = New TableView(h) As "TView"
    .Name = "TView_" & iCount
    .Expand = True
    .Columns.Count = 2
    .Columns[0].Text = "TView_" & iCount
    .Columns[1].Text = "i 2"
    .Header = .Horizontal
    .Mode = Select.Single

    Inc .Rows.Count
    tv[.Rows.Max, 0].Text = "oo"
    tv[.Rows.Max, 1].Text = "the data of oo"

    Inc .Rows.Count
    tv[.Rows.Max, 0].Text = "aa"
    tv[.Rows.Max, 1].Text = "the data of aa"

    h.Height = (.Rows.Height * 2) + Style.FrameWidth + .Columns.Height ' set the tableview height
  End With

  Dim vb As New VBox(h) ' add some control buttons like delete
  vb.Width = 40
  vb.Spacing = True
  Try vb.Centered = True
  Dim b As New Button(vb) As "btnDel"
  b.AutoResize = True
  b.Picture = Picture["icon:/16/delete"]
  b.Tag = h

End

' the delete button, the buttons .Tag is set to it's containing panel so we  use that to remove the container
Public Sub btnDel_Click()

  Dim hb As Panel = Last.Tag

  For Each o As Object In hb.Children
    If Object.Type(o) = "VBox" Then o.Children.Clear
    o.Delete
  Next
  hb.Delete

End

the things being displayed do not make a lot of sense but the point is to show how it could be easier to not use a TableView at the top level due to the restrictions.

With the IDE you could make another form that is the template for each panel and keep adding that to the scrollview.

As for your current issue with your current method i would suggest using unique Names or parenting but i do not know how you are getting the data as you have not explained that so i cannot point out the error.

in my example above i have used the delete buttons .Tag to point to the correct container , i could also have used Last.Parent.Parent in the btnDel_Click() event
Attachments
_aa-0.0.7.tar.gz
(12.59 KiB) Downloaded 83 times
Untitled.png
Untitled.png (105.42 KiB) Viewed 950 times
If at first you don't succeed , try doing something differently.
BruceS
seany
Posts: 32
Joined: Friday 6th December 2019 3:09pm

Re: Inserting a table in a tabel cell

Post by seany »

I still want a way to quickly show that one table is a subtable of another table. I do have a scrollview, containing the main table, which expands or contracts, based on its cell contents, and then i can clearly show that one table is a subtable .

So for example, i can have in the outer table, samples 1 ... N, each corresponding to a row. And then (take the example of sample 6) I can show each sample in 3 columns. First column = column 0 is serial num, like 1, 2, ... N. The second one is an automatic generated Random key. In the third column (so cellrow = 5, cellcolumn = 3) I can add another table, and then hold param1, ... paramK each in a row. Now in this table, each row can have 2 columns, first one ( = index 0) the param Name (such as param1) and the second one the param value. I want to do this in arbitrary depth.

This sort of visualization is needed.

I will probably also have to add an "expand / collapse" button pair to ensure that the total view does not get out of hand.
seany
Posts: 32
Joined: Friday 6th December 2019 3:09pm

Re: Inserting a table in a tabel cell

Post by seany »

I can now do this, to arbitrary depth

Image

I want to get rid of the scrollbars in the middle, and make it possible, that
  1. The subtables move, based on whether an element is added or deleted above it,
  2. The subtables can be deleted post adding
  3. The subtables can be expanded and collapsed. Collapse should affect all the other tables that are subtables to it.
I add the relevant form and class. They are not Fmain.

Any help is appreciated.
Attachments
Archiv.zip
(4.2 KiB) Downloaded 78 times
Post Reply