B4J Question [SOLVED] Add SwiftButton into B4XTable at the first-column (edit-delete-duplicate)...

Magma

Expert
Licensed User
Longtime User
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
Yes, you can load any layout you like.

Based on that example:
1643961931998.png


B4X:
B4XTable1.BuildLayoutsCache(B4XTable1.MaximumRowsPerPage)
Sleep(0) 'let the table resize
For i = 1 To editCol.CellsLayouts.Size - 1
    Dim p As B4XView = editCol.CellsLayouts.Get(i)
    Dim LayoutParent As B4XView = xui.CreatePanel("")
    p.AddView(LayoutParent, 0, 0, p.Width, p.Height)
    LayoutParent.LoadLayout("Item")
Next

You need to hide the items on the empty rows (as done in the original example).

Note that this example was created before the Void column type was available. It would have been better to set the "edit" column type to Void.
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
about VOID... type.. somewhere you are saying that this column ignored when setting data... when setting data you mean with B4XTable1.SetData(data)...?

When the Data for example is a List and every row has a string array... before void (using text) i was adding in first index of array (0) a column/empty-null string (so needed noofcolumns+1 for the empty) ---> now what's the exactly difference if void type selected ?
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
You need to hide the items on the empty rows (as done in the original example).
Well i am creating layout - using the code gave me (the diffenrence from simple controls was... xui.createpanel)... the controls in layout already visible false...

But when trying to show them up - getting error:
B4X:
Private Sub B4XTable1_DataUpdated
    For i = 0 To B4XTable1.VisibleRowIds.Size - 1
        Dim p As B4XView = editcol.CellsLayouts.Get(i + 1)
        'p.GetView(1).Visible = B4XTable1.VisibleRowIds.Get(i) > 0     '<--------------- I think that's because those aren't views into celllayout but at the created xui panel.... but how i will find and make it visible...
        'p.GetView(2).Visible = p.GetView(1).Visible
        'p.GetView(3).Visible = p.GetView(1).Visible
    Next
    'ie.DataUpdated
End Sub

..i am so confused with b4xview...
I think that's because those aren't views into celllayout but at the created xui panel.... but how i will find them and make them visible...?
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
when trying to show them up - getting error:
B4X:
Private Sub B4XTable1_DataUpdated
    For i = 0 To B4XTable1.VisibleRowIds.Size - 1
        Dim p As B4XView = editCol.CellsLayouts.Get(i + 1)
        p.LoadLayout("item")  'since you are putting the items in Designer layout, load the item layout or whatever name you gave it
    Next
End Sub
This will show you the swift buttons, but I think you need more work to modify: Sub GetRowId (View As......because the SwiftButton is not a B4XView and you have to get to its mBase parent
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
Well... after hours i ve managed how to visible layout...

but i coming to the point - where Sender is not Sender ... and cast so now what... ??

my way to make visible the layout - and when not needed hide:
B4X:
Private Sub B4XTable1_DataUpdated
    thistable.Refresh

    For i = 0 To B4XTable1.VisibleRowIds.Size - 1

    Dim p As B4XView = editcol.CellsLayouts.Get(i + 1)

    If B4XTable1.VisibleRowIds.Get(i) > 0 Then
            Dim p As B4XView = editcol.CellsLayouts.Get(i + 1)
            For Each v As B4XView In p.getAllViewsRecursive
                v.Visible=True
            Next

    Else
            Dim p As B4XView = editcol.CellsLayouts.Get(i + 1)
            For Each v As B4XView In p.getAllViewsRecursive
                v.Visible=False
            Next

    End If

    Next
   
    'ie.DataUpdated
End Sub

but the problem now... is
How the layout with swift buttons will know the index of row and tell that when clicked... ?

that is for standard buttons - created on the fly:
B4X:
Dim getmap As Map = B4XTable1.GetRow(GetRowId(Sender))

but for swift buttons ?
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
B4X:
    LoadData
   
    table1.MaximumRowsPerPage = 15
    table1.BuildLayoutsCache(B4XTable1.MaximumRowsPerPage)
    If xui.IsB4J Then B4XTable1.HighlightSearchResults = False
   

'    For i = 1 To editcol.CellsLayouts.Size - 1
'        Dim p As B4XView = editcol.CellsLayouts.Get(i)
'        p.AddView(CreateButton("btnEdit", Chr(0xF044)), 2dip, 5dip, 40dip, 40dip)
'        p.AddView(CreateButton("btnDelete", Chr(0xF00D)), 44dip, 5dip, 40dip, 40dip)
'        'p.AddView(CreateButton("btnDuplicate",Chr(0xF0C5)), 85dip, 5dip, 40dip, 40dip)
'    Next
   

    Sleep(0) 'let the table resize
    For i = 1 To editcol.CellsLayouts.Size - 1
    'For i = 1 To B4XTable1.VisibleRowIds.Size - 1
        Dim p As B4XView = editcol.CellsLayouts.Get(i)
       

        Dim p2 As B4XView= xui.CreatePanel("")

        p.AddView(p2, 0, 0, p.Width, p.Height)
        p2.tag=i
        p2.LoadLayout("control1")
       
        'for Each v As B4XView In p.getAllViewsRecursive
        '    v.Visible=False
        'Next
        'Dim LayoutParent As B4XView = xui.CreatePanel("")
        'p.AddView(LayoutParent, 0, 0, p.Width, p.Height)
        'LayoutParent.LoadLayout("control1")
        'LayoutParent.Visible=False
        'p.LoadLayout("control2")
       
    Next

B4X:
Private Sub btnedit_Click

   
    Dim RowIndex As Int = btnedit.mBase.Parent.tag
    Log(RowIndex)
    Dim RowId As Long = B4XTable1.VisibleRowIds.Get(RowIndex)

noooo... i am stucked... can i have a full example with swift buttons / clicked and return rowindex... rowid. ? please... ?
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
You might be confusing people with your code snippets. Maybe, if you post your project or a small one someone may find it easier to help you.
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
You are right... here it is...

If anyone have the time for editing it - will be very helpful (i think for all) to have an example with swiftbuttons/layout... that will response/return the row of data...
 

Attachments

  • B4XTableAndForms-swiftbuttons-try.zip
    8.6 KB · Views: 111
Upvote 0

Mahares

Expert
Licensed User
Longtime User
ll) to have an example with swiftbuttons/layout.

Here is a fully operational B4J prohect using B4Xtable Editable with swift buttons. If you improve on it and I am sure you can, please share the project., You project that you posted would not compile as it was missing files, but I did not need it.

1644337511378.png
 

Attachments

  • B4XTableMagmaProjectForForum.zip
    12.7 KB · Views: 139
Last edited:
Upvote 1

Mahares

Expert
Licensed User
Longtime User
I am uploading a little different approach... It is the same compile error as experienced in the first one
I still cannot run your revised version:
B4X:
B4J Version: 9.30
Parsing code.    (0.14s)
    Java Version: 11
Building folders structure.    (0.02s)
Running custom action.    Error
-------------------------------------------------------------------------------
   ROBOCOPY     ::     Robust File Copy for Windows                              
-------------------------------------------------------------------------------
  Started : Tuesday, February 8, 2022 11:44:10 AM
   Source : C:\Temp\Junk\B4XTable\B4XTAB~1\Shared Files\
     Dest : C:\Temp\Junk\B4XTable\B4XTAB~1\B4J\Files\
    Files : *.*
        
  Options : *.* /DCOPY:DA /COPY:DAT /R:1000000 /W:30 
------------------------------------------------------------------------------
2022/02/08 11:44:10 ERROR 2 (0x00000002) Accessing Source Directory C:\Temp\Junk\B4XTable\B4XTAB~1\Shared Files\
The system cannot find the file specified.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I am uploading a little different approach...
ok. I commented this line and it is ok now. Thank you
B4X:
#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files"

I tested your project you just loaded, but the Edit and Del do not work
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Mahares.. just download right click
I mentioned to you in post 13 that I got it working, but the Edit and Delete buttons do not wok. Why did you upload it that way. The project I gave you in post 10, they all work:; Edit Del, duplicate
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
Sorry but is working (different approach has to do with using Tag and not loading template again and again) ... only duplcate/add i didn;t check -that works too but not showing buttons... - I will check them again now - one moment to check add-duplicate too
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
here it is... hope it's ok - duplicate-add-showing add-edit-dup buttons too at the new rows... using tag for rowindexing
 

Attachments

  • B4XTableMagmaProjectForForum-different-approach.zip
    15.4 KB · Views: 137
Last edited:
Upvote 0
Top