Wish B4X Table new feature

BlueVision

Well-Known Member
Licensed User
Longtime User
It would be nice if a B4XTable could be additionally configured in the following way (for example, via the table setup in the Designer):

When searching via the search field with a negative result, the table becomes empty. In this case, would it be possible to display a freely definable string in the middle of the empty table in the table setup to indicate this? This could certainly be achieved through programming. However, this is relatively cumbersome and requires a corresponding amount of effort for many tables in the programme.
 

PaulMeuris

Well-Known Member
Licensed User
The B4XTable has a public variable to set the text of the message.
B4X:
    B4XTbl1.StringNoMatches = " Nichts gefunden!"
This message appears in the place where the lblFromTo (= public variable) normally is shown.
You can modify the appearance of that label but it also has an effect on the normal text when there is some data.
1756720990068.png

A possible solution (added to the library by Erel of course) could be to use a message box as you can see in the image above.
Code to add:
B4X:
            If mLastRowIndex = -1 Then
                lblFromTo.Text = StringNoMatches
                xui.MsgboxAsync(StringNoMatches,"No matches")
EDIT:
And of course a public string can hold the title of the message box.
B4X:
    Public StringTitleNoMatches As String = "No matches"
The message box will then be:
B4X:
xui.MsgboxAsync(StringNoMatches,StringTitleNoMatches)
And you set the title in your code by:
B4X:
    B4XTbl1.StringTitleNoMatches = "Suche Ergebnisse"
1756722144781.png
 
Last edited:

LucaMs

Expert
Licensed User
Longtime User
This could certainly be achieved through programming. However, this is relatively cumbersome and requires a corresponding amount of effort for many tables in the programme.
Create your own Snippet.

B4X:
Sub B4XTable1_DataUpdated

    Dim ScrollViewParent As B4XView
    ScrollViewParent = B4XTable1.clvData.sv.Parent
    Dim B4XTableMsgExists As Boolean
    Dim pnlB4XTableMsg As B4XView
    For Each xSomeView As B4XView In ScrollViewParent.GetAllViewsRecursive
        If xSomeView.Tag = "No matches panel" Then
            pnlB4XTableMsg = xSomeView
            B4XTableMsgExists = True
            Exit
        End If
    Next
  
    If B4XTableMsgExists Then
        pnlB4XTableMsg.Visible = False
    End If

    Dim mLastRowIndex As Int
    mLastRowIndex = GetB4XTableLastRowIndex(B4XTable1)
    If mLastRowIndex = - 1 Then
        If B4XTableMsgExists Then
            pnlB4XTableMsg.Visible = True
        Else
            pnlB4XTableMsg = xui.CreatePanel("")
            pnlB4XTableMsg.Tag = "No matches panel"
            pnlB4XTableMsg.SetLayoutAnimated(0, B4XTable1.clvData.sv.Left, B4XTable1.clvData.sv.Top, B4XTable1.clvData.sv.Width, B4XTable1.clvData.sv.Height)
            pnlB4XTableMsg.Color = xui.Color_Red
            Dim lblB4XTableMsg As Label
            lblB4XTableMsg.Initialize("")
            Dim B4XTableLabelLeft, B4XTableLabelTop, B4XTableLabelWidth, B4XTableLabelHeight As Int
            B4XTableLabelWidth = 100dip
            B4XTableLabelHeight = 50dip
            B4XTableLabelLeft = (pnlB4XTableMsg.Width - B4XTableLabelWidth) / 2
            B4XTableLabelTop = (pnlB4XTableMsg.Height - B4XTableLabelHeight) / 2
            pnlB4XTableMsg.AddView(lblB4XTableMsg, B4XTableLabelLeft, B4XTableLabelTop, B4XTableLabelWidth, B4XTableLabelHeight)
            lblB4XTableMsg.Text = "No data"
            ScrollViewParent.AddView(pnlB4XTableMsg,B4XTable1.clvData.sv.Left, B4XTable1.clvData.sv.Top, B4XTable1.clvData.sv.Width, B4XTable1.clvData.sv.Height)
        End If
    End If
End Sub

Public Sub GetB4XTableLastRowIndex(tbl As B4XTable) As Int
    Dim r As Reflector
    r.Target = tbl
    Return r.GetField("_mlastrowindex")
End Sub


We could optimize the code but using global variables.
 

BlueVision

Well-Known Member
Licensed User
Longtime User
Wow mates, thanks for responding. Looks very nice what I see here, have to sort it out and decide the best way of implementation. (using 13 tables in my programme).
You are fantastic!
 
Top