B4J Question Add row to table view using an array of nodes

le_toubib

Active Member
Licensed User
Longtime User
hi all ,
i'm trying to add a row to a tableview, using an array of nodes , with the following line :

.items.add:
TableView1.Items.Add(ArrayOfNodes)

however this is the result that i get :
error.jpg


the added row is not showing the nodes.
p.s: the 1st 3 rows were previously added successfully via a list of arrays (data) :
TableView1.Items=data:
TableView1.Items=data

what am i doing wrong?
 

jkhazraji

Active Member
Licensed User
Longtime User
hi all ,
i'm trying to add a row to a tableview, using an array of nodes , with the following line :

.items.add:
TableView1.Items.Add(ArrayOfNodes)

however this is the result that i get :
View attachment 155807

the added row is not showing the nodes.
p.s: the 1st 3 rows were previously added successfully via a list of arrays (data) :
TableView1.Items=data:
TableView1.Items=data

what am i doing wrong?
Make them children and use the parent:
1722607541061.png
 
Last edited:
Upvote 0

behnam_tr

Active Member
Licensed User
Longtime User
B4X:
dim rows(9) as object

rows(0) = creattextfieldsub

.

.

rows(6) = creatcomboboxsub

..



TableView1.Items.Add(rows)



__________________

sub creattextfieldsub as textfield

 dim tx as textfield

tx.initilize("")

tx.text="your default text"

return tx



end sub
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
B4X:
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private xui As XUI 
    Private Button1 As B4XView
    Private table1 As TableView
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1")
    MainForm.Show
    table1.Initialize("tab1")
    table1.SetColumns(Array("a","b","c"))
    table1.SetColumnWidth(0,100)
    table1.SetColumnWidth(1,100)
    table1.SetColumnWidth(2,100)
    MainForm.RootPane.AddNode(table1,0,0,320,300)
    'add 6 rows
    For a = 0 To 5
        Dim el As Label
        el.Initialize("el")
        el.Text ="label" & a
        Dim co As ComboBox
        co.Initialize("co")
        Dim bu As Button
        bu.Initialize("bu")
        bu.Text = "button" & a
        addToTable(table1,Array(el,co,bu))
    Next
End Sub

Sub Button1_Click
    xui.MsgboxAsync("Hello World!", "B4X")
End Sub

Sub addToTable(table As TableView, obs() As Object)
    table.Items.Add(obs) 
End Sub

Sub el_MouseClicked (EventData As MouseEvent)
    Dim lab As Label = Sender
    Log(lab.Text)
End Sub
 
Upvote 1

behnam_tr

Active Member
Licensed User
Longtime User
B4X:
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private xui As XUI
    Private Button1 As B4XView
    Private table1 As TableView
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1")
    MainForm.Show
    table1.Initialize("tab1")
    table1.SetColumns(Array("a","b","c"))
    table1.SetColumnWidth(0,100)
    table1.SetColumnWidth(1,100)
    table1.SetColumnWidth(2,100)
    MainForm.RootPane.AddNode(table1,0,0,320,300)
    'add 6 rows
    For a = 0 To 5
        Dim el As Label
        el.Initialize("el")
        el.Text ="label" & a
        Dim co As ComboBox
        co.Initialize("co")
        Dim bu As Button
        bu.Initialize("bu")
        bu.Text = "button" & a
        addToTable(table1,Array(el,co,bu))
    Next
End Sub

Sub Button1_Click
    xui.MsgboxAsync("Hello World!", "B4X")
End Sub

Sub addToTable(table As TableView, obs() As Object)
    table.Items.Add(obs)
End Sub

Sub el_MouseClicked (EventData As MouseEvent)
    Dim lab As Label = Sender
    Log(lab.Text)
End Sub

any way to add more than one node in same row??
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
that example adds a label a combobox and a button into each row

1722615581394.png
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
if you don't want to use the sub just do
B4X:
'addToTable(table1,Array(el,co,bu))
'use
table1.items.add(array(el, co, bu))
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
B4X:
    For a = 0 To 5
        Dim el As Label
        el.Initialize("el")
        el.Text ="label" & a
        Dim co As ComboBox
        co.Initialize("co")
        Dim bu As Button
        bu.Initialize("bu")
        bu.Text = "button" & a
        Dim te As TextField
        te.Initialize("te")
        'creat a pane
        Dim pa As Pane
        pa.Initialize("pa")
        ' add the nodes to the pane
        pa.AddNode(bu,0,0,70,20)
        pa.AddNode(te,75,0,125,20)
        'add the pane as an item to table
        table1.Items.Add(Array(el,co,pa))
    Next
1722618862983.png
 
Last edited:
Upvote 0
Top