B4A Library Grid/Table and ListView Library

This library allows to create easely grids/tables and
from version 2.50
list views too!
Enjoy!
:)

The original post has been moved
http://www.b4x.com/android/forum/threads/grid-library.16381/page-10#post-168452"

Version 2.50 beta
- Added support for multiline rows

Version 2.51 beta
- Bug fixes

Version 2.52 beta
- Added Typeface support for rows and hedaer

Version 2.53
- Added SingleLine property for columns

sample code and usage hints can be found here
http://www.b4x.com/android/forum/threads/grid-library.16381/page-15#post-194602

Version 2.55
- Added object b4aActivityContext

Version 2.56
- Added and modified event hendlers
https://www.b4x.com/android/forum/threads/grid-and-listview-library.16381/page-19#post-297198

Version 2.57
- Added Columns Builders
https://www.b4x.com/android/forum/threads/grid-and-listview-library.16381/page-19#post-299406

Version 2.58
- Bug fixes

Version 2.59
- Added RowHeight for each column
- Added HeaderHeight for each column
https://www.b4x.com/android/forum/threads/grid-and-listview-library.16381/page-19#post-304465

Version 2.60
- Added TouchX() and TouchY()
- Added FirstVisiblePosition() and LastVisiblePosition()
https://www.b4x.com/android/forum/threads/grid-and-listview-library.16381/page-19#post-304905

Version 2.65
- Added Button Columns
https://www.b4x.com/android/forum/threads/grid-and-listview-library.16381/page-19#post-306507

Version 2.67
- Added CellProps event
- Removed PropSetColor / PropSetTextColor
https://www.b4x.com/android/forum/threads/grid-table-and-listview-library.16381/page-19#post-307490

Version 2.71
- Added OnSelectAllow event
- Added selection on row background
https://www.b4x.com/android/forum/threads/grid-table-and-listview-library.16381/page-21#post-347618

Version 2.73
- Added OnRowProps event
https://www.b4x.com/android/forum/threads/grid-table-and-listview-library.16381/page-21#post-349404

Version 2.76
- Fixed dubug log bug
https://www.b4x.com/android/forum/threads/grid-table-and-listview-library.16381/page-21#post-375965

If you like my grid.
You can support the development.


 

Attachments

  • xnGridSample200beta.zip
    3.6 KB · Views: 2,066
  • xnGrid2xx_1.png
    xnGrid2xx_1.png
    77.2 KB · Views: 5,136
  • xnObjects267.zip
    75.7 KB · Views: 800
  • xnObjects272.zip
    87.2 KB · Views: 600
  • xnObjects273.zip
    87.5 KB · Views: 695
  • xnObjects276.zip
    87.2 KB · Views: 1,445
Last edited:

stefanobusetto

Active Member
Licensed User
Longtime User
right! here it is!

SelectRow ( int n )
selects the row number n
works also in multiselect mode

BulkSetLength ( int n )
gets ready the grid to be loaded with n rows

all the following requires a prior BulkSetLength

BulkSetRow ( int n , String values() )
sets the contents of the row number n row using the data of the values() array
BulkMapSetRow ( int n , Map m )
the same as the previous but the data are loaded from the map
BulkCursorSetRow ( int n , Cursor c )
the same as the previous but the data are loaded from the cursor

BulkCursorAppend ( Cursor c , int RowStart , int RowEnd )
sets the contents of the grid loading from the cursor
starting from the RowStart row of the cursor
to the RowEnd row of the cursor
the RowStart row of the cursor will become the 0 row of the grid
the RowStart +1 row of the cursor will become the 1 row of the grid
and so on ...

:)
 

stefanobusetto

Active Member
Licensed User
Longtime User
If you set a custom horizontal gravity
you must set also the vertical one.
The standard vertical gravity is GRAVITY. CENTER_VERTICAL so...
I hope i've been clear
:)
 

stefanobusetto

Active Member
Licensed User
Longtime User
@mahares
vertical scroll is not good if you also set the horizontal one
since now i had no ideas on how to improve this
there are two nested scrollviews with no code associated
your idea sounds interesting may you post a simple
example code ?
tia
stefano
 

Mahares

Expert
Licensed User
Longtime User
@Stefano: The 2 new methods work very well. ScrollDown position at the last record, ScrollUp position at the first record in the list. I do not know if this is possible or not: Highlight the row when it scrolls to first or last to make it more visual. It can enhance the methods, although it is not paramount.
Thank you for always striving to make it better.
 

Mahares

Expert
Licensed User
Longtime User
Thank you in advance Stefano: I have figured it out:
To go to last row and highlight it:
B4X:
gg.ScrollDown
gg.selectrow(gg.RowCount-1)
To go to first row and highlight it:
B4X:
gg.ScrollUp
gg.selectrow(0)
 

molder26

Member
Licensed User
Longtime User
@mahares: scrollup and scrolldown are really nice!
Will be nice too an EnsureVisible function to any row specific not only top and bottom like listview have in VB6.
Your lib is the best ;)
Regards
 

robh

Member
Licensed User
Longtime User
Column Name

Is there a method I can call to rerieve the column name e.g.
gg.GetColumnName(colIndex)?

Many thanks
 

Mahares

Expert
Licensed User
Longtime User
I did not see a method like the one you describe in the Grid library either, but here is my thought: When you defined the columns, you had to give them names as strings or string array elements. You can use those variables to retrieve any column name. See below sample: Stefano, the library architect may offer a better solution than the one I use as a workaround:


B4X:
Dim cc(2) As xnGridCol
Dim A As String  :A="F_0"
Dim B As String  :B="F_1"

cc(0).Initialize2 ( A , A , 40dip , Gravity.FILL)
gg.AppendCol ( cc(0) )
cc(1).Initialize2 (B , B , 120dip , Gravity.CENTER_VERTICAL )
gg.AppendCol ( cc(1) )
 

stefanobusetto

Active Member
Licensed User
Longtime User
@robh
i've added the required feature in version 1.61
B4X:
gg.GetColumn(colIndex)?

@mahares
thanks for your help pal
 

stefanobusetto

Active Member
Licensed User
Longtime User
at last i was able to add the grid lines support
far (very far!) to be a final release now works decently on ics and gingerbread
there are otherwise major issues on honeycomb (mainly redraw problems)

to have the gird lines set
B4X:
GridWidth = 1dip
or whatever you like

on some devices grid lines are drawn wrong (see attached example images)
if you get a wrong drawing yust set
B4X:
GridWidthTextOffset = ...
GridWidthCheckOffset = ...

in the sample code i've posted the values working for ics and honeycomb

obviously i'm trying to compute the adjustments automatically
so if you are going to post the values working for your device
may be i'll be able to figure out sooner the solution (tia :))
 

Attachments

  • wrong.png
    wrong.png
    3.3 KB · Views: 203
  • correct.png
    correct.png
    3.2 KB · Views: 199

Mahares

Expert
Licensed User
Longtime User
@Stefano: The GRID lines method look superb. They are classy. I will be your Guinea pig. I tested on the following devices:
Phone OS 4.04: 560x940, Scale=1.5, 240 dpi
7" tablet OS 4.03: 480x800, Scale=1
7" tablet OS 2.2: 480x800, Scale=1
All 3 tests look great. I have 3 foods for thought for next version if possible:
1. Ability to change the color of the GridWidth lines.
2. Ability to turn on and off horizontal and/or vertical lines.
3. Ability to center, or left or right postion the text inside the cells (between grid lines) so the grid lines do not touch the text.
 

stefanobusetto

Active Member
Licensed User
Longtime User
thanks a lot
i did some tests on all the devices i'has able to put my hands on
but not more the 6 or 7 models so your experience is highly valuable

did you change GridWidthTextOffset or GridWidthCheckOffset ?
or the values i've posted where fine?

as for the requests
the first is already done. i forgot to put the reference in the post! :BangHead:
B4X:
gg.GridColor = ...

the others are already under construction
i've done some preliminary test for the third.
:D
 

Mahares

Expert
Licensed User
Longtime User
did you change GridWidthTextOffset or GridWidthCheckOffset ?
or the values i've posted where fine?
I did not have to change any offsets or even mess with them on the devices I tested. The grids look fine without them.

I also just checked the GridColor method. It works great.
 

robh

Member
Licensed User
Longtime User
Row Add/Remove

I have an existing grid which has been initialized and displays on screen perfectly with a number of rows.

Later in code I want to remove the existing rows and add some new rows to the grid.

I have tried dg.deleterows which removes the rows as expected leaving just the existing grid and it's header in place however, the problem being that when I attempt to add new rows, the rows get added to the underlying grid object OK but the rows are never display on screen?

So to sum up.

1)Create Grid with x cols, x rows
2) remove existing rows
3) add some rows

Rows in step 3 are never drawn on screen?

Edit: I Forgot to mention, if I comment out the dg.deleterows, then the additional rows I am appending to the grid in step 3 are displayed in the grid?
 
Last edited:

robh

Member
Licensed User
Longtime User
may you post source code
please

Hi Steffano

As a test I have done the following:

dg.AppendRow ( Array As String (dataLine.sku,dataLine.descr,dataLine.total,dataLine.month0,dataLine.month1,dataLine.month2,dataLine.month3, _
dataLine.month4,dataLine.month5,dataLine.month6,dataLine.month7,dataLine.month8,dataLine.month9, _
dataLine.month10,dataLine.month11,dataLine.total))


' test clear down of existing row - this works, rows are cleared off screen
dg.DeleteRows


' now add a new row - row is added to rows collection but not displayed on screen

dg.AppendRow ( Array As String (dataLine.sku,dataLine.descr,dataLine.total,dataLine.month0,dataLine.month1,dataLine.month2,dataLine.month3, _
' dataLine.month4,dataLine.month5,dataLine.month6,dataLine.month7,dataLine.month8,dataLine.month9, _
' dataLine.month10,dataLine.month11,dataLine.total))



If I comment out the dg.deleterows line, I get 2 rows displayed in my grid.

hope that helps.

Thank you.
 

stefanobusetto

Active Member
Licensed User
Longtime User
it is a bug!!!
since you delete all rows then insert new ones
you can call GridCreate(...) to repaint
i'll fix the bug as soon as possible
thanks for the bug report
:)

a tip
if you go advanced
you can use the "#" button
to have the b4a code formatted
:D
 
Top