Hi Erel,
I have begun to use the B4A Table CustomView.
In the B4XTable1.CellClicked (ColumnId As String, RowId As Long) routine the RowID begins with 1, why?
We are all used that indexes begin with 0, why does it begin here with 1?
Trying
B4X:
mp = bxtTable.GetRow()
Log(mp.Get(ColumnId))
Returns null.
I put Wish as the prefix, because I would like to have this index coherent with all the others.
Well, I read the original thread of the B4XTable and didn't find anything about the RowID beginning with 1.
I will live with it, but I find it a bit disturbing.
Well, I read the original thread of the B4XTable and didn't find anything about the RowID beginning with 1.
I will live with it, but I find it a bit disturbing.
No, it doesn't return 0.
It returns the correct value!
I use it with a SQLite database and I memorize the rowids of the database rows in a List, there the first index is 0.
To read in the database the selected row i need to use CurrentIndex = RowId - 1.
I've noticed that you're somewhat reluctant to give me a "Like", Klaus.
Who knows, maybe every now and then, among the many nonsense I write, sometimes an exact thing will happen ?.
It is not important, of course: I am unable to eat them ?
LucaMS is correct. If I click on the 10th row of the data here is what I get:
B4X:
Log($"rowId: ${RowId} "$ ) '10 which is row # clicked. Note that header cell is 0, then cell 1 then 2, etc.
Dim mp As Map
mp.Initialize
mp = B4XTable1.GetRow(RowId)
Log(mp) 'shows: col name and the number 10 if I clicked the 10th row excluding the header row
My stored data column name is: Entry and the cell content for the 10th row is 10, since my data starts with 1, then 2, then 3, etc.
1. The RowId is a random unique value. Don't assume that it starts from 1. The only thing that you can assume is that RowId = 0 means an empty row. I use it all the time in the DataUpdated event.
If you want to get the visible row number then you must use B4XTable.VisibleRowIds.
2. You need to add 1 when you want to get the "CellLayout" of a visible row from Column.CellLayouts. It happens because the first layout is the header layout.
Example that marks rows where the value of a column is larger than 10:
B4X:
Sub B4XTable1_DataUpdated
For i = 0 To B4XTable1.VisibleRowIds.Size - 1
Dim RowId As Long = B4XTable1.VisibleRowIds.Get(i)
If RowId > 0 Then 'non-empty row
Dim Value As Double = B4XTable1.GetRow(RowId).Get(numberColumn.Id)
If Value > 10 Then
SetRowColor(i, xui.Color_LightGray)
Continue '<----
End If
End If
SetRowColor(i, xui.Color_White)
Next
End Sub
Sub SetRowColor (RowIndex As Int, Clr As Int)
For Each c As B4XTableColumn In B4XTable1.VisibleColumns
Dim pnl As B4XView = c.CellsLayouts.Get(RowIndex + 1) '+1 because of the header
pnl.Color = Clr
Next
End Sub
Don't worry, in my real code I use only the RowID and it works.
I simply supposed that ColumnId and RowID were the indexes of the column and the row and not IDs with a different meaning.
The reason of this thread was the wish to be coherent with all B4X objects having indexes beginning with 0.
Calling a column name or column header ColumnID is also a bit confusing because you always think of ID as a number when it comes to database. It should have been named: ColumnHeader or ColumnName
The same here: B4XTable1.GetRow(RowId).Get(numberColumn.Id) Id is normally reserved for a number but here it is the column content. It should have been named: ColumnContent or ColumnValue
Calling a column name or column header ColumnID is also a bit confusing because you always think of ID as a number when it comes to database. It should have been named: ColumnHeader or ColumnName
The same here: B4XTable1.GetRow(RowId).Get(numberColumn.Id) Id is normally reserved for a number but here it is the column content. It should have been named: ColumnContent or ColumnValue
2. Don't confuse ID with an index. ID doesn't need to be a number. There is an important distinction between the column title and its id. In most cases they are the same but they don't need to be the same. The ID is an internal field that the user never sees.