jahswant Well-Known Member Licensed User Longtime User Apr 14, 2023 #1 Is there a simple way to make B4XTable Fit Screen Size. I don't want horizontal scroll !
Solution M M Mahares Apr 14, 2023 jahswant said: I just want a snippet to make it auto adapt to screen size. Click to expand... Here is another way: Code: 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: Code: 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
jahswant said: I just want a snippet to make it auto adapt to screen size. Click to expand... Here is another way: Code: 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: Code: 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 Expert Licensed User Longtime User Apr 14, 2023 #2 EasyCode - Form/B4XTable Generator with no writting code [B4J] [B4A] 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... www.b4x.com You mean this ? Upvote 0
EasyCode - Form/B4XTable Generator with no writting code [B4J] [B4A] 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... www.b4x.com You mean this ?
jahswant Well-Known Member Licensed User Longtime User Apr 14, 2023 #3 Thanks I just want a snippet to make it auto adapt to screen size. Thanks for the links. Upvote 0
Magma Expert Licensed User Longtime User Apr 14, 2023 #4 jahswant said: Thanks I just want a snippet to make it auto adapt to screen size. Thanks for the links. Click to expand... 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: Code: 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 Upvote 0
jahswant said: Thanks I just want a snippet to make it auto adapt to screen size. Thanks for the links. Click to expand... 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: Code: 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
M Mahares Expert Licensed User Longtime User Apr 14, 2023 #5 jahswant said: simple way to make B4XTable Fit Screen Size Click to expand... Bonjour: Another quick and simple way: Code: 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 Upvote 0
jahswant said: simple way to make B4XTable Fit Screen Size Click to expand... Bonjour: Another quick and simple way: Code: 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
jahswant Well-Known Member Licensed User Longtime User Apr 14, 2023 #6 Magma said: anarraywiththesizes( Click to expand... what is this variable please ? Upvote 0
Magma Expert Licensed User Longtime User Apr 14, 2023 #7 An int that will use with col.width next like mahares.. Upvote 0
M Mahares Expert Licensed User Longtime User Apr 14, 2023 #8 jahswant said: I just want a snippet to make it auto adapt to screen size. Click to expand... Here is another way: Code: 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: Code: 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 Upvote 0 Solution
jahswant said: I just want a snippet to make it auto adapt to screen size. Click to expand... Here is another way: Code: 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: Code: 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
jahswant Well-Known Member Licensed User Longtime User Apr 14, 2023 #9 Thanks. Mahares said: Bonjour Click to expand... Bonne soirée. Upvote 0
jahswant Well-Known Member Licensed User Longtime User Jun 18, 2023 #10 @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 Upvote 0
@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
M Mahares Expert Licensed User Longtime User Jun 18, 2023 #11 jahswant said: could you help me make this code work properly ? Click to expand... 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 Last edited: Jun 18, 2023 Upvote 0
jahswant said: could you help me make this code work properly ? Click to expand... 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