Android Question SQL db Data to FlexGrid

Enthousiastic

Active Member
Licensed User
Dear forum, in my question on February 5, 2021 on how to put data in Flegrid, you answered me :
"There is no automatic method.
To populate FlexGrid with a DB, you need to read each row of the DB and insert it with the AddRow (Cell As Object (), Refresh As Boolean) method.
Refresh is best set False and then use the invalidate method to update the view "
Because so far I have not been able to accomplish anything specific, please can you send me a small example.
I want to proceed to a database that I have created for my books. Please do not take it like laziness, but I do not have your knowledge and skills.
Many , many thanks in advanced.
 

José J. Aguilar

Expert
Licensed User
I don't know if there is some FlexiGrid + DB example, but you can see one with B4XTable:


**EDITED: Not relevant, as klaus says in the next post, the OP is talking about [B4X] [XUI] SD FlexGrid (Table).
About FlexiGrid I'm not sure if you're talking about Flexible Table, you can see in the main thread:
EDIT: LucaMs has written a routine to fill a table with a Remote Database Connector query result see post 182.
The routine hasn't been added into the Class for the reasons explained in post 183.
A sample program can be found HERE.
 
Last edited:
Upvote 0

Star-Dust

Expert
Licensed User
Dear forum, in my question on February 5, 2021 on how to put data in Flegrid, you answered me :
"There is no automatic method.
To populate FlexGrid with a DB, you need to read each row of the DB and insert it with the AddRow (Cell As Object (), Refresh As Boolean) method.
Refresh is best set False and then use the invalidate method to update the view "
Because so far I have not been able to accomplish anything specific, please can you send me a small example.
I want to proceed to a database that I have created for my books. Please do not take it like laziness, but I do not have your knowledge and skills.
Many , many thanks in advanced.
Find an example at post # 2 of the library thread. Click the link below

 
Last edited:
Upvote 0

Mahares

Expert
Licensed User
Because so far I have not been able to accomplish anything specific, please can you send me a small example.
Let me start by saying this is the first time I try this library. It is a good one, but I am fully satisfied using B4XTable which gives me much of what I need. But, in order to help you out, I created this attached project using the FlexGrid library where data on the grid is populated from a SQLite database table. I hope this can be of help to you if you want to continue using it.
Here is some of the code. Full project is attached:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout1")    
    FlexGrid1.ColsName=Array As String("Id","Author","BookTitle")
    FlexGrid1.ColsWidth=Array As Int(75dip,200dip,400dip)
    FlexGrid1.ColsType=Array As Int(FlexGrid1.TypeInt,FlexGrid1.TypeString,FlexGrid1.TypeString)
    FlexGrid1.ColsAlignment=Array As String("CENTER","LEFT","LEFT")
    FlexGrid1.setFont(xui.CreateDefaultBoldFont(18))
    Dim rs As ResultSet = Starter.oSQL.ExecQuery2("SELECT * FROM Library", Null)
    Do While rs.NextRow
        FlexGrid1.AddRow(Array As Object(rs.GetLong("Id"), rs.GetString("Author"), rs.getstring("BookTitle")),True)
    Loop
    rs.Close  
    Log(FlexGrid1.RowCount)
End Sub
 

Attachments

  • flexgridUsingSQLite062821.zip
    31.4 KB · Views: 57
  • flexgridSQLite.png
    flexgridSQLite.png
    20 KB · Views: 92
Upvote 0

Star-Dust

Expert
Licensed User
Let me start by saying this is the first time I try this library. It is a good one, but I am fully satisfied using B4XTable which gives me much of what I need. But, in order to help you out, I created this attached project using the FlexGrid library where data on the grid is populated from a SQLite database table. I hope this can be of help to you if you want to continue using it.
Here is some of the code. Full project is attached:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout1")   
    FlexGrid1.ColsName=Array As String("Id","Author","BookTitle")
    FlexGrid1.ColsWidth=Array As Int(75dip,200dip,400dip)
    FlexGrid1.ColsType=Array As Int(FlexGrid1.TypeInt,FlexGrid1.TypeString,FlexGrid1.TypeString)
    FlexGrid1.ColsAlignment=Array As String("CENTER","LEFT","LEFT")
    FlexGrid1.setFont(xui.CreateDefaultBoldFont(18))
    Dim rs As ResultSet = Starter.oSQL.ExecQuery2("SELECT * FROM Library", Null)
    Do While rs.NextRow
        FlexGrid1.AddRow(Array As Object(rs.GetLong("Id"), rs.GetString("Author"), rs.getstring("BookTitle")),True)
    Loop
    rs.Close 
    Log(FlexGrid1.RowCount)
End Sub
The peculiarity of SD_FlexGrid is that you do not have to navigate in the table divided into pages but sliding in 2 directions. That you can do math calculations like formulas in a similar way to excel. And the way you can select cells in group.
 
Upvote 0

Enthousiastic

Active Member
Licensed User
A very big thank you, to all of you ,from the bottom of my heart , because I have spent nights to find a solution and now thanks to you, I will proceed with the implementation of the database. God bless you, stay healthy and safe !!!!!!! :):):):):):):):)
 
Upvote 0

Peter Simpson

Expert
Licensed User
I created this attached project using the FlexGrid library where data on the grid is populated from a SQLite database table.

Nice one @Mahares,
I didn't have the time to do this for @Enthousiastic yesterday, but I already have an example using MSSQL using the 'Chinook' album database using this great library by @Star-Dust that I was thinking about converting for @Enthousiastic, I popped on here today fully expecting not to see the answer. I was going to quickly convert my MSSQL 'Chinook' example to use the original SQLite 'Chinook' database over for @Enthousiastic to learn from, but I see that you've already done it.

Anyway, your code is an excellent example on how to integrate SQLite (or any database for that matter) to work with DS_FlexGrid 👍

I hope this can be of help to you if you want to continue using it.
He's bound too ;)


Cheers 🍷
 
Upvote 0

Mahares

Expert
Licensed User
A very big thank you, to all of you ,from the bottom of my heart
We know you are very appreciative. We are very glad to see members benefit from answers posted by others. That is the motto of B4X community. Another form of appreciation, might be for you to click the 'Like' button when you have benefited from a thread's post in addition to your comments or in lieu of a response.
 
Upvote 0

AnandGupta

Well-Known Member
Licensed User
Another form of appreciation, might be for you to click the 'Like' button when you have benefited from a thread's post in addition to your comments or in lieu of a response.
And edit the title of this thread as '[Solved]' so that members can find the solution here.
 
Upvote 0
Top