B4A Library Grid/Table and ListView Library

stefanobusetto

Active Member
Licensed User
Longtime User
hi Volker
"Array As String(aSpalten)" returns an arry of 1 item

B4X:
Sub bt_test_click
Dim col As Int
col = 4

Dim kZeile  As String
kZeile  = "a;b;c;d"

' split into fZeile() 
Dim fZeile() As String
fZeile = Regex.Split(";", kZeile )

' copy from fZeile() to aSpalten()
Dim aSpalten(fZeile.Length) As String
For i = 0 To fZeile.Length - 1 
    aSpalten(i) = fZeile(i) 
Next

' ok 4 items
Log ( fZeile.Length )

' ok 4 items
Log ( aSpalten.Length )

' copy to aResult() 
Dim aResult() As String
aResult = Array As String ( aSpalten )

' only 1 item
Log ( aResult.Length )

Log ( "----------------" )

' --------------------------
Dim col As Int
col = 4

Dim kZeile  As String
kZeile  = "a;b;c;d"

' split into fZeile() 
Dim fZeile() As String
fZeile = Regex.Split(";", kZeile )

If fZeile.Length = col Then
   ' copy to aResult() 
   Dim aResult(fZeile.Length) As String
   For i = 0 To fZeile.Length - 1 
       aResult(i) = fZeile(i) 
   Next
   
   ' ok 4 items
   Log ( aResult.Length )

End If

End Sub

i think you can use the follwing code
B4X:
Dim Tr As TextReader
Dim kZeile As String
Dim aSpalten(col) As String col is a known index

Tr.Initialize(File.OpenInput(File.DirAssets, "demo.txt"))
kZeile = Tr.ReadLine
Do While kZeile <> Null
Dim fZeile() As String
If kZeile.Length > 0 Then
    fZeile=Regex.Split(";", kZeile)
    If fZeile.Length = col Then
        Tabelle.AppendRow(fZeile) 
    End If
End If   
kZeile = Tr.ReadLine   
Loop
Tr.Close
 

androidvh

Member
Licensed User
Longtime User
Hallo Stefano,

coming up a new question.

I try to copy selected row´s in a new grid.

It is very slow and I didn´t find anything to copy
a row directly to the new grid.
watch my code , perhaps there is another solution....

For i = 0 To Tabelle.RowsSelected.Length - 1
Dim kZeile As String
Dim sZeile() As String
For p = 0 To Tabelle.ColCount - 2
kZeile= kZeile & Tabelle.GetValue(Tabelle.RowsSelected(i),p) & ";"
Next

kZeile = kZeile & Tabelle.GetValue(Tabelle.RowsSelected(i),p)
sZeile =Regex.split(";", kZeile)
Tabelleselk.AppendRow(sZeile)
Next

Tabelleselk.GridCreate2(False, True)


kind regards Volker
 

stefanobusetto

Active Member
Licensed User
Longtime User
hi Volker
how many rows and cols are there in the destination table?
what do you mean for slow? 1sec , 2sec , ...

if you prefer you could also avoid to store the data
of the source row in a delimited string you can use a map
or an array directly and then call then MapAppendRow or
AppendRow methods

you could also avoid to compute the selected row for each
iteration of the loop
B4X:
rs = Tabelle.RowsSelected(i)
For p = 0 To Tabelle.ColCount - 2
kZeile= kZeile & Tabelle.GetValue(rs,p) & ";"
Next
 

androidvh

Member
Licensed User
Longtime User
map

Hallo Stefano,

thanks for your reply.
Now it is much faster.
I process a grid 20 * 500 elements
120 selected, now 2 seconds in the new grid

Please can you show how map is working with
your grid. (special copy a row and append in new grid)
I don´t see the tree in the forest...

kind regards

Volker
 

stefanobusetto

Active Member
Licensed User
Longtime User
if you have for example, a grid with 4 columns
B4X:
   Dim cc(4) As xnGridCol

   cc(0).Initialize2 ( "Cod." , "cod" , 40dip , Gravity.LEFT )
   gg.AppendCol ( cc(0) )

   cc(1).Initialize2 ( "Des." , "des" , 120dip , Gravity.LEFT )
   gg.AppendCol ( cc(1) )

   cc(2).Initialize2 ( "Grp." , "grp" , 60dip , Gravity.LEFT )
   gg.AppendCol ( cc(2) )

   cc(3).Initialize2 ( "Other" , "other" , 100dip , Gravity.LEFT )
   gg.AppendCol ( cc(3) )

you can add a row using AppendRow
B4X:
gg.AppendRow ( Array As String ( "1" , "1" , "1" , "1" ) )
gg.AppendRow ( Array As String ( "2" , "2" , "2" , "2" ) )
the array you pass to the AppendRow must have 4 elements
because the grid has 4 columns

but if you use MapAppendRow
B4X:
Dim m As Map
m.Initialize
m.Put("cod","a")
gg.MapAppendRow(m)
m.Initialize
m.Put("des","b")
gg.MapAppendRow(m)
you can pass to the MapAppendRow a map
with less then 4 elements
and you can set the value by name!

 

TFD

New Member
Licensed User
Longtime User
Hello,

is it possible to jump to a row? With SelectRow it is possible to select the row, but the grid doesn't scroll to the selected row.

Thanks
 

stefanobusetto

Active Member
Licensed User
Longtime User
there are 2 methods
ScrollDown
ScrollUp
to scroll the grid to the first row or
to the last row
that's what you need?
 

Discorez

Member
Licensed User
Longtime User
Hello, Stefano!
I can't to compile your sample.
I use B4A v2.52, xnObjects v1.63
B4A shows this error:
 

TFD

New Member
Licensed User
Longtime User
there are 2 methods
ScrollDown
ScrollUp
to scroll the grid to the first row or
to the last row
that's what you need?

I know these 2 methods, but I don't want to scroll to the top or bottom. I just want to scroll to a certain position.
For example: my grid has 100 rows. Now i can select row 50 with the selectrow method. This only selects row 50, but does not scroll to row 50. So I cannot see the highlighted row until I scroll there with my finger.
It would be nice to jump to that row and show it.
 

aviario

Active Member
Licensed User
Longtime User
Hi.

Firs of all sorry for may bad english.
We are trying your grid.
We asking if is posible align header and rows with diferent horizotal position.
We use initiazed2 center_horizontal in some columns, in another columns use left, but we want center_horizontal all columns of header and depending of type of data, align center, left or right rows.

Is posible, formating numbers in one column?

Thanks.
 

stefanobusetto

Active Member
Licensed User
Longtime User
@discorez
i've compiled with no problems the sample project
with xnObject 1.67
i use jdk1.6.0_30
if you want i can send the sample project again
please let me know
 

Attachments

  • xnObjects.zip
    53.8 KB · Views: 235

stefanobusetto

Active Member
Licensed User
Longtime User
@aviario

don't worry for your english
mine is not much better

there is no way to set a gravity of the header
and a different one for the rows
this is indeed a nice feature i'll add to a furure release

as for the number format
the content of a cell is text you can format
as you like

 

aviario

Active Member
Licensed User
Longtime User

Thanks for your reply

Another question. Is posible hidden cols?

Thanks again
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…