B4J Question Assign an Event Name to Nodes

oldeast

Active Member
Licensed User
Longtime User
I created a some buttons as nodes, with a tag,
I would like to assign them all the same event name to retrieve the tag

Create Buttons:
Sub CreateButtons
    Dim btnMenu(120) As Button
    Dim TopStart As Int:TopStart=140
    Dim Top As Int:Top=1
    Dim left As Int:left=1
    Dim Count As Int:Count=0
    Dim mp As Map:Dim lst As List
    
    lst.initialize
    strquery="SELECT MenuItemID from MenuItem order by MenuCode"
    DBUtils.ExecuteList(Main.SQL1,strquery,Null,0,lst)
    
    For i= 0 To lst.Size-1
        
        strQuery1="Select MenuitemID, MenuItem.menuCode,MenuItem.menuitem, MenuGroup.GroupName, MenuGroup.GroupNumber from MenuGroup INNER JOIN MenuItem on MenuGroup.GroupID=Menuitem.GroupID where menuitemID=" &lst.Get(i)& " ORDER BY MenuCode"
        mp.initialize
        mp=DBUtils.ExecuteMap(Main.SQL1,strQuery1,Null)
        'create 14 button per row
        If Count=14 Then
            Top=(((i)/14)*80)
            left=1
            Count=0
        End If
        
        btnMenu(i).Initialize(Null)
        btnMenu(i).Tag=mp.Get("menucode")
        btnMenu(i).TextSize=12
        btnMenu(i).Text=mp.Get("groupname")&CRLF&mp.Get("menucode")&CRLF&mp.Get("menuitem")
        btnMenu(i).WrapText=True
        btnMenu(i).Id=(i)

        frmOrderSelect.RootPane.AddNode(btnMenu(i),(left*Count)*100,Top+TopStart,100,80)
        Count=Count+1
    Next
    
End Sub


Thanks
Graham
 
Solution
Attached your modified project.
It contains:
CheckBoxes added by code without layout, the common EventName is defined in the code.
CheckBoxes added by code with layout, the common EventName is defined in the Designer.
B4XSwitchss added by code with layout, the common EventName is defined in the Designer.
When you add views with LoadLayout you need to add those in MainForm_Resize otherwise the last added View is not positioned correctly.

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

oldeast

Active Member
Licensed User
Longtime User
No Eventprefix because I didn't know how to name the event.
Thanks for the code link, I will use that example.
Graham
 
Upvote 0

oldeast

Active Member
Licensed User
Longtime User
I have modified my code, and added the EventName and loaded the layout for each node.
The event does not fire.
I don't understand how the button object in the Event is related to the created button node.
thanks
G

B4X:
Sub CreateButtons As Button
    Dim TopStart As Int:TopStart=140
    Dim Top As Int:Top=1
    Dim left As Int:left=1
    Dim Count As Int:Count=0
    Dim mp As Map:Dim lst As List
    
    lst.initialize
    strquery="SELECT MenuItemID from MenuItem order by MenuCode"
    DBUtils.ExecuteList(Main.SQL1,strquery,Null,0,lst)
    
    For i= 0 To lst.Size-1
        
        strQuery1="Select MenuitemID, MenuItem.menuCode,MenuItem.menuitem, MenuGroup.GroupName, MenuGroup.GroupNumber from MenuGroup INNER JOIN MenuItem on MenuGroup.GroupID=Menuitem.GroupID where menuitemID=" &lst.Get(i)& " ORDER BY MenuCode"
        mp.initialize
        mp=DBUtils.ExecuteMap(Main.SQL1,strQuery1,Null)
        'create 14 button per row
        If Count=14 Then
            Top=(((i)/14)*80)
            left=1
            Count=0
        End If
        
        btnOrder.Initialize(btnOrder_Action)
        btnOrder.Tag=mp.Get("menucode")
        btnOrder.TextSize=12
        btnOrder.Text=mp.Get("groupname")&CRLF&mp.Get("menucode")&CRLF&mp.Get("menuitem")
        btnOrder.WrapText=True
        btnOrder.Id=i
        
        
        frmOrderSelect.RootPane.LoadLayout("OrderSelect")
        frmOrderSelect.RootPane.AddNode(btnOrder,(left*Count)*100,Top+TopStart,100,80)
        Count=Count+1
        
    Next
    
End Sub

Sub btnOrder_Action
    Dim btn1 As Button
    Log("click")
    Try
btn1 =Sender
Log( btn1.tag)
Catch
    Log (LastException)
    
    End Try
End Sub
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
have modified my code, and added the EventName and loaded the layout for each node.
You are still doing it wrong!
Views added by the designer should NOT be Initialized. It is initialized when loading the Layout!
The Event-Prefix must be set in the designer for sure.
 
Upvote 0

oldeast

Active Member
Licensed User
Longtime User
in the example I read..
example:
Sub Globals
    Private B4XSwitch1 As B4XSwitch
End Sub
which is what I did.. the equivalent button
I haven't anything in the designer, the form is empty.
I must be totally misundersanding this..
its 11pm, thanks for your help
 
Upvote 0

oldeast

Active Member
Licensed User
Longtime User
I recreated the example as a project.
I cannot get it to work even for a single iteration.
Any help appreciated.
 

Attachments

  • Check.zip
    2 KB · Views: 118
Upvote 0

klaus

Expert
Licensed User
Longtime User
Attached your modified project.
It contains:
CheckBoxes added by code without layout, the common EventName is defined in the code.
CheckBoxes added by code with layout, the common EventName is defined in the Designer.
B4XSwitchss added by code with layout, the common EventName is defined in the Designer.
When you add views with LoadLayout you need to add those in MainForm_Resize otherwise the last added View is not positioned correctly.
 

Attachments

  • CheckNew.zip
    3.4 KB · Views: 121
Upvote 0
Solution

oldeast

Active Member
Licensed User
Longtime User
Thanks very much Klaus, I understand it now.
Much appreciated.
Graham
 
Last edited:
Upvote 0
Top