Android Question B4A editable table

Andyclick125

Member
Licensed User
I have a problem with a table. I'm using 3 columns in the table. But only the first column is my "data" column which will be loaded from a csv file and can be modified by the user. The second clumn and the third column should be used for descriptions only (no user access). My problem now is after loading the data I do not know how can I modifiy certain cells in the 2nd and 3rd column by code, how can I lock it that nobody can adjust it and how can I export the first row only (only the data). Currently I have the situation if I export the data I get a list of values and 2 from 3 values are "null". I think this is because I have no data in column 2 and 3.
 

Attachments

  • Table.PNG
    11 KB · Views: 263
  • ExportList.PNG
    991 bytes · Views: 182

Andyclick125

Member
Licensed User
Hi Erel! I solved the problem with "null" with that code (see below). But I have 3 additional problems: 1.) I need only integer without fractions. But with the formatter I used in my code I could not remove. 2.) I want remove the "comma" in the "item1" column but I tried several methods without success. 3.) I'm working with 3 different apps with 3 different names but I can't install all 3 programs in parallel. If I install one and later on I want to install a second I will asked if I want to update the first? I think there are some parameters which must be adjusted but I have no idea.
[Public Sub ExportTableToCSV
Dim c As B4XTableColumn
Dim List As List
List.Initialize

Dim formatter As B4XFormatter
formatter.Initialize
c = B4XTable1.Columns.Get(0)
formatter.Initialize
c.Formatter = formatter
Dim Positive As B4XFormatData = c.Formatter.NewFormatData
Positive.TextColor = B4XTable1.TextColor
Positive.FormatFont = xui.CreateDefaultFont(16)
Positive.MaximumFractions = 0
Positive.MinimumFractions = 0
Positive.MinimumIntegers = 1
' Positive.FractionPaddingChar.Trim
' Positive.DecimalPoint = False
c.Formatter.AddFormatData(Positive,0,255, True)

Dim rs As ResultSet = B4XTable1.sql1.ExecQuery("SELECT * FROM data")
Do While rs.NextRow
Dim row(1) As String
row(0) = rs.GetString(c.SQLID)
If row(0) > 255 Then
row(0) = 255
Else If row(0) < 0 Then
row(0) = 0
End If
List.Add(row(0))
Loop
rs.Close......]
 
Upvote 0

Andyclick125

Member
Licensed User
Thanks for hint
B4X:
Public Sub ExportTableToCSV
    Dim c As B4XTableColumn
    Dim List As List
    List.Initialize
'    Dim cnt As Int
    Dim formatter As B4XFormatter
    formatter.Initialize
    c = B4XTable1.Columns.Get(0)
    formatter.Initialize
    c.Formatter = formatter
    Dim Positive As B4XFormatData = c.Formatter.NewFormatData
    Positive.TextColor = B4XTable1.TextColor
    Positive.FormatFont = xui.CreateDefaultFont(16)
    Positive.MaximumFractions = 0
    Positive.MinimumFractions = 0
    Positive.MinimumIntegers = 1
'    Positive.FractionPaddingChar.Trim
'    Positive.DecimalPoint = False
    c.Formatter.AddFormatData(Positive,0,255, True) 'Inclusive (zero included)c.Formatter.AddFormatData(Positive, 0, c.Formatter.MAX_VALUE, True)

    Dim rs As ResultSet = B4XTable1.sql1.ExecQuery("SELECT * FROM data")
    Do While rs.NextRow
        Dim row(1) As String
            row(0) = rs.GetString(c.SQLID)
            If row(0) > 255 Then
                row(0) = 255
            Else If row(0) < 0 Then
                row(0) = 0
            End If
            List.Add(row(0))
    Loop
    rs.Close
    If List.Size = 204 Then          
        File.WriteList(......
 
Upvote 0

Andyclick125

Member
Licensed User
Hi Erel. If I use your proposed code the stored csv file contains fraction again. It seems the code will be ignored because I'm using same in other function (user interface) and there it works fine. If a user enters a fraction it will be rounded to integer.
 

Attachments

  • stored_file.PNG
    3.7 KB · Views: 139
Last edited:
Upvote 0

Andyclick125

Member
Licensed User
Hi Erel! Thanks for your hint. I found a way now how I can modify. I'm not sure if it is java straight forward but it works. The values will be modified right after the enter event...
B4X:
Wait For (Dialog.ShowTemplate(InputTemplate, "OK", "", "CANCEL")) Complete (Result As Int)
            If Result = xui.DialogResponse_Positive Then
               
                If InputTemplate.Text.Contains(".") Then
                    If InputTemplate.Text > 99 Then
                        InputTemplate.Text = InputTemplate.Text.SubString2(0,3)
                    Else if InputTemplate.Text > 9 And InputTemplate.Text <=99 Then
                        InputTemplate.Text = InputTemplate.Text.SubString2(0,2)
                    Else
                        InputTemplate.Text = InputTemplate.Text.SubString2(0,1)
                    End If
                    ToastMessageShow("No fraction allowed. Use only integer values!", True)
                End If
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…