iOS Question FlexGrid Problem

tariqyounis

Member
Licensed User
Longtime User
each line is duplicated, can you please advice what I have to do, I am using iSD_FlexGrid (Version: 0.01)

code to add row:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    'load the layout to Root
    Root.LoadLayout("pgBasket")
    fgBasket.ColsName=Array As String("الرمز","اسم الصنف","المبلغ","العدد","الخصم","النسبة")
    Log("basket")
    Dim s As Int = lbl_titl3.Width
    Log(s)
    fgBasket.ColsWidth=Array As Int(s*20/100,s*36/100,s*11/100,s*11/100,s*11/100,s*11/100)
    fgBasket.ColsType=Array As Int(fgBasket.TypeString ,fgBasket.TypeString,fgBasket.TypeString,fgBasket.TypeString,fgBasket.TypeString,fgBasket.TypeString)
    fgBasket.ColsAlignment=Array As String("CENTER","CENTER","CENTER","CENTER","CENTER","CENTER")
End Sub

Private Sub B4XPage_Appear
    For i =  fgBasket.RowCount -1 To 0 Step -1
        fgBasket.RemoveRow(i)
    Next
    Main.items(Main.max_item_order,1) = ""

    For i = 1 To 99
        If Main.items(i,1).Length>0 Then
            fgBasket.AddRow(Array As Object(Main.items(i,1),Main.items(i,2),Main.items(i,7),Main.items(i,5),Main.items(i,6),Main.items(i,8)),True)
            fgBasket.SetRowHeight(i-1,60dip)
        End If
    Next
End Sub
flexgriderror.jpeg
 

Star-Dust

Expert
Licensed User
Longtime User
It appears that you delete the items and reinsert them. Try the clear method:


B4X:
Private Sub B4XPage_Appear
    fgBasket.ClearRow  ' Try this
    Main.items(Main.max_item_order,1) = ""

    For i = 1 To 99
        If Main.items(i,1).Length>0 Then
            fgBasket.AddRow(Array As Object(Main.items(i,1),Main.items(i,2),Main.items(i,7),Main.items(i,5),Main.items(i,6),Main.items(i,8)),True)
            fgBasket.SetRowHeight(i-1,60dip)
        End If
    Next
End Sub

Update the library with the latest version
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Thank you for your reply, unfortunately the system crashed. I thing I was using my old method RemoveRow(i) becuase of this crash.
Send me an example that controls
 
Upvote 0

tariqyounis

Member
Licensed User
Longtime User
I got the error from line 11 and 16 after I applied fgBasket.ClearRow. the error from line 11: <B4IExceptionWrapper: Error Domain=caught_exception Code=0 " *** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array" UserInfo={NSLocalizedDescription= *** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array}>
and the error from line 16 is: <B4IExceptionWrapper: Error Domain=caught_exception Code=0 " *** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array" UserInfo={NSLocalizedDescription= *** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array}>

B4X:
Private Sub B4XPage_Appear
'    For i =  fgBasket.RowCount -1 To 0 Step -1
'        fgBasket.RemoveRow(i)
'       
'    Next
    fgBasket.ClearRow  ' Try this
    Main.items(Main.max_item_order,1) = "
    For i = 1 To 99
        If Main.items(i,1).Length>0 Then
            Try
                fgBasket.AddRow(Array As Object(Main.items(i,1),Main.items(i,2),Main.items(i,7),Main.items(i,5),Main.items(i,6),Main.items(i,8)),True)
            Catch
                Log(LastException)
            End Try
            Try
                fgBasket.SetRowHeight(i-1,60dip)
            Catch
                Log(LastException)
            End Try
        End If
    Next
End Sub
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
On line 11 it appears an array Item error. What I understand is the index at position i is empty.
To test this, replace the line like this. Eliminating Item should give you no error but populate the grid. If so, then the error is certainly in Main.Item
B4X:
fgBasket.AddRow(Array As Object($"Item${I}"$,$"Item${I}A"$,$"Item${I}B"$,$"Item${I}C"$,$"Item${I}D"$,$"Item${I}E"$) ,True)
'If you want to setthe height of the row you can do it with Add2 when you populate the grid
'fgBasket.AddRow2(Array As Object($"Item${I}"$,$"Item${I}A"$,$"Item${I}B"$,$"Item${I}C"$,$"Item${I}D"$,$"Item${I}E"$) ,60dip,True)
I have a doubt, are the number of columns thrown into the grid the same as what you enter?
Enter 6 columns of data and then you should have 6 columns of headers into design.
If after this change it gives you an error, it means that the number of columns set in the design does not match the number of columns in the data

______________________________________________________________________________________________________________
As for line 16, post me the exact error, but that also most likely depends on the fact that line i-1 doesn't exist.
Always check the number of lines with fgBasket.RowCount. The highest row is FlexGrid1.RowCount-1

B4X:
' Try
'    fgBasket.SetRowHeight(i-1,60dip)
' Catch
'     Log(LastException)
'  End Try
if i-1<fgBasket.RowCount then fgBasket.SetRowHeight(i-1,60dip)

But you don't need to change the height of the row later, you can use Add2 and set the height as you populate the grid
B4X:
fgBasket.AddRow2(Array As Object(Main.items(i,1),Main.items(i,2),Main.items(i,7),Main.items(i,5),Main.items(i,6),Main.items(i,8)),60dip,True)
 
Last edited:
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Update to version 0.06 you can have the number of columns by code. You can edit your source in this way

B4X:
    fgBasket.ClearRow  ' Try this
    Main.items(Main.max_item_order,1) = "
    For i = 1 To 99
        Dim SingleItems() As String = Array As Object(Main.items(i,1),Main.items(i,2),Main.items(i,7),Main.items(i,5),Main.items(i,6),Main.items(i,8))
        If SingleItems(0).Length>0 Then
            If fgBasket.ColCount=SingleItems.Length Then fgBasket.AddRow2(SingleItems,60dip,True)
        End If
    Next
 
Last edited:
Upvote 0
Top