Dim w As Int = B4XTable1.mBase.Width
w = Root.Width
Dim l As List
l.Initialize
Dim k As Int
l.AddAll(Array As Double(.20, .15, .10, .40, .10, .05))
For Each col As B4XTableColumn In B4XTable1.Columns
col.Width=l.Get(k)*w
k=k+1
Next
And another:
B4X:
Dim l As List
l.Initialize
Dim k As Int
l.AddAll(Array As Int(20%x, 15%x, 10%x, 40%x, 10%x, 5%x))
For Each col As B4XTableColumn In B4XTable1.Columns
col.Width=l.Get(k)
k=k+1
Next
Well, I ve decided to create a Form-View Generator (B4J - B4A)... that creates Forms with B4XTable + with no writing code at all... The Designer is in B4J code, the produced code/files working at B4A too !!! - It uses SQLite, easily can change at any SQL Database (mysql, mssql... etc) - You...
OK This was for stretch as the screenshot of link - post (if you get in you will see it - i am not trying to sell anything)... check the snippet... here:
B4X:
Dim allcolwidth As Int=editcol.Width
Dim colpadding As Int=0
Dim newwidth As Int = 0
Dim formwidth As Int = B4XPages.GetNativeParent(Me).Width - (table1.mBase.Left * 2) 'remove the distance of b4xtable1 from width
For i = 0 To B4XTable1.Columns.Size-1
Dim thiscol As B4XTableColumn = B4XTable1.Columns.get(i)
allcolwidth=allcolwidth+thiscol.width+colpadding
Next
If allcolwidth<formwidth Then 'this will need the opposite...
Dim cw As Int = ((formwidth)-(allcolwidth)) / (B4XTable1.Columns.Size.Length) 'also here opposite... then you will divide it by the size of columns
'Log(cw)
For i = 0 To B4XTable1.Columns.Size-1
Dim thiscol As B4XTableColumn = B4XTable1.Columns.get(i)
newwidth=thiscol.width+cw ' and you will use (-)
anarraywiththesizes(i)=newwidth 'you will use after the loops... to set them
Next
End If
You can use this... but the opposite ...if the size-total of widths is bigger
Dim w As Int = B4XTable1.mBase.Width
w = Root.Width
Dim numberofcols As Int =6 'or any other number for your columns
For Each col As B4XTableColumn In B4XTable1.Columns
col.Width=w/numberofcols 'you can alternatively assign different widths to dif cols
Next
Dim w As Int = B4XTable1.mBase.Width
w = Root.Width
Dim l As List
l.Initialize
Dim k As Int
l.AddAll(Array As Double(.20, .15, .10, .40, .10, .05))
For Each col As B4XTableColumn In B4XTable1.Columns
col.Width=l.Get(k)*w
k=k+1
Next
And another:
B4X:
Dim l As List
l.Initialize
Dim k As Int
l.AddAll(Array As Int(20%x, 15%x, 10%x, 40%x, 10%x, 5%x))
For Each col As B4XTableColumn In B4XTable1.Columns
col.Width=l.Get(k)
k=k+1
Next
@Magma or @Mahares could you help me make this code work properly ?
B4X:
(ArrayIndexOutOfBoundsException) java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
B4X:
Public Sub MakeTableFitScreenSize(B4XTable1 As B4XTable,B4XTableEditCol As B4XTableColumn)
Dim anarraywiththesizes() As Int
Dim allcolwidth As Int = B4XTableEditCol.Width
Dim colpadding As Int=0
Dim newwidth As Int = 0
Dim formwidth As Int = B4XPages.GetNativeParent(Me).Width - (B4XTable1.mBase.Left * 2) 'remove the distance of b4xtable1 from width
For i = 0 To B4XTable1.Columns.Size-1
Dim thiscol As B4XTableColumn = B4XTable1.Columns.get(i)
allcolwidth=allcolwidth+thiscol.width+colpadding
Next
If allcolwidth<formwidth Then 'this will need the opposite...
Dim cw As Int = ((formwidth)-(allcolwidth)) / (B4XTable1.Columns.Size) 'also here opposite... then you will divide it by the size of columns
Log(cw)
For i = 0 To B4XTable1.Columns.Size-1
Dim thiscol As B4XTableColumn = B4XTable1.Columns.get(i)
newwidth=thiscol.width+cw ' and you will use (-)
anarraywiththesizes(i)=newwidth 'you will use after the loops... to set them
Next
End If
End Sub
I hope this helps if I am understanding your code and post. But if you set the number of columns in this below line, in your sub
the code will work and not crash. If the table number of cols is 4 put 4
Dim anarraywiththesizes(Numberofcolumns) As Int
You could also do it this way: Dim anarraywiththesizes(B4XTable1 .Columns.Size) As Int
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.