SQLitening Support Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Welcome to the SQLitening support forums!

Author Topic: Auto Populate Listview with SQLite Records  (Read 5047 times)

Fredrick Ughimi

  • Master Geek
  • ****
  • Posts: 601
    • View Profile
    • Software Development Company
Auto Populate Listview with SQLite Records
« on: October 02, 2018, 05:49:05 PM »

Hello,

I have an application that runs on a LAN. A Listview is populated with sqlite records by another system on the network.
How can I display the records saved without needing to close and reopen the Listview - auto display the records
saved while Listview is on display.

Best regards.
Logged
Fredrick O. Ughimi

fughimi@yahoo.com
- Freedom lies in being bold -- Robert Frost, Poet

cj

  • Master Geek
  • ****
  • Posts: 696
    • View Profile
Re: Auto Populate Listview with SQLite Records
« Reply #1 on: October 03, 2018, 01:07:51 PM »

What you are doing might require reading some changes table, updating array, redisplay current screen if necessary.
There might be an easy way, but don't have a solution.

The good news:
Virtual listviews and grids only need to refresh at an interval to see if something changed that is currently in view.
While scrolling through pages they are current.
If you sit on a page, refresh the page every so often in a loop, timer, thread using the last executed SQL statement.

'only called at an interval like every so many seconds using a timer
sdata = RefreshData(sql)                 'get current screen data
IF sdata <> sDataBefore THEN         'something has changed
  sdatabefore = sdata                     'set values equal
  'refresh page
END IF


Code: [Select]
#INCLUDE "sqlitening.inc"
FUNCTION PBMAIN () AS LONG 'autoupdate.bas
 RANDOMIZE
 LOCAL sTest,sdata,sdatabefore,sql AS STRING, x AS LONG
 KILL "junk1.db3"
 ERRCLEAR
 sql   = "select * from t1"
 slOpen "junk1.db3","C"
 slexe  "create table if not exists t1(c1)"
 FOR x = 1 TO 100
  IF x MOD 10 = 0 THEN slexe "insert into t1 values('hello')"

  sdata = RefreshData(sql)                        'get current screen data
  IF sdata <> sDataBefore THEN                    'something has changed
    sdatabefore = sdata                           'set values equal
    sTest+= USING$("New screen when x=#",x) + $CR 'only for test purposes
  END IF
 NEXT

 ? sTest,%MB_SYSTEMMODAL,"Screen updates"

END FUNCTION

FUNCTION RefreshData(sql AS STRING) AS STRING
 DIM sArray() AS STRING
 slSelAry sql,sArray(),"Q9C"
 FUNCTION = JOIN$(sArray(),$CR)
END FUNCTION
« Last Edit: October 03, 2018, 01:21:35 PM by cj »
Logged
CJ

Fredrick Ughimi

  • Master Geek
  • ****
  • Posts: 601
    • View Profile
    • Software Development Company
Re: Auto Populate Listview with SQLite Records
« Reply #2 on: October 03, 2018, 02:36:18 PM »

Thanks CJ.

I thought as much. Would take a look at your codes.
« Last Edit: October 03, 2018, 02:48:43 PM by Fredrick Ughimi »
Logged
Fredrick O. Ughimi

fughimi@yahoo.com
- Freedom lies in being bold -- Robert Frost, Poet

Fredrick Ughimi

  • Master Geek
  • ****
  • Posts: 601
    • View Profile
    • Software Development Company
Re: Auto Populate Listview with SQLite Records
« Reply #3 on: October 05, 2018, 12:24:09 PM »

Hello CJ,

I could not get it to work. Partly because I did not know where to place some of the codes in my IDE.
I did try this though:

Code: [Select]
Case %WM_PAINT
   FOR x = 1 TO 100
  IF x MOD 10 = 0 THEN

  sdata = RefreshData(sql)                        'get current screen data
  IF sdata <> sDataBefore THEN                    'something has changed
    sdatabefore = sdata                           'set values equal
    sTest+= USING$("New screen when x=#",x) + $CR 'only for test purposes
  END IF
  end if
 NEXT

I used a crude method (reset and reload listview) that only works when a form is minimised and then restored.
Nothing happens if it just sits there.
Code: [Select]
Case %WM_PAINT
  LISTVIEW RESET hDlg, id&
  LISTVIEW SET TEXT hDlg, id&, item&, col&, slFN("Surname")
  LISTVIEW SET TEXT hDlg, id&, item&, col&, slFN("Othernames")
  LISTVIEW SET TEXT hDlg, id&, item&, col&, slFN("Category")
Logged
Fredrick O. Ughimi

fughimi@yahoo.com
- Freedom lies in being bold -- Robert Frost, Poet

cj

  • Master Geek
  • ****
  • Posts: 696
    • View Profile
Re: Auto Populate Listview with SQLite Records
« Reply #4 on: October 05, 2018, 12:26:40 PM »

I only use grids or a huge multiline textbox.
Does PowerDev or what you use have a control for this?
Logged
CJ

Fredrick Ughimi

  • Master Geek
  • ****
  • Posts: 601
    • View Profile
    • Software Development Company
Re: Auto Populate Listview with SQLite Records
« Reply #5 on: October 05, 2018, 01:38:33 PM »

I have a license for MLG and I tried using it. The Refresh would not display the new records entered.

You know where I can download the latest version of MLG? I have version 3.0.
Logged
Fredrick O. Ughimi

fughimi@yahoo.com
- Freedom lies in being bold -- Robert Frost, Poet

cj

  • Master Geek
  • ****
  • Posts: 696
    • View Profile
Re: Auto Populate Listview with SQLite Records
« Reply #6 on: October 05, 2018, 01:39:56 PM »

Just know that Gary Beene would have to be contacted.
Logged
CJ

Fredrick Ughimi

  • Master Geek
  • ****
  • Posts: 601
    • View Profile
    • Software Development Company
Re: Auto Populate Listview with SQLite Records
« Reply #7 on: October 05, 2018, 01:46:45 PM »

I did contact Gary. No response. I even posted in the PB forum. No response either. In the main time I can make do with the version I have.
Logged
Fredrick O. Ughimi

fughimi@yahoo.com
- Freedom lies in being bold -- Robert Frost, Poet

Fredrick Ughimi

  • Master Geek
  • ****
  • Posts: 601
    • View Profile
    • Software Development Company
Re: Auto Populate Listview with SQLite Records
« Reply #8 on: October 05, 2018, 08:08:08 PM »

Hello CJ,

I finally did got a response from Gary Beene.

I want to save a selected row from MLG to SQLitening. Any ideas?

I something similar to what Mike provided a while ago on the PB Forums

https://forum.powerbasic.com/forum/user-to-user-discussions/third-party-addons/61266-mlg-questions/page2

Post #36.

Looking now at the very insightful codes Mike wrote I see that the columns are predefined. It would always not be that way in the real world.



Logged
Fredrick O. Ughimi

fughimi@yahoo.com
- Freedom lies in being bold -- Robert Frost, Poet

Bern Ertl

  • Master Geek
  • ****
  • Posts: 496
  • Excellent
    • View Profile
    • InterPlan Systems
Re: Auto Populate Listview with SQLite Records
« Reply #9 on: October 08, 2018, 09:30:24 AM »

I am using SQLitening in conjunction with a grid control (Farpoint's Spread).  I usually add a hidden column or two for each row to save the rowID (and possibly other data) when populating the grid control with data.  When any of the data is edited, it's easy to look up the corresponding rowID and update the database.



Fredrick Ughimi

  • Master Geek
  • ****
  • Posts: 601
    • View Profile
    • Software Development Company
Re: Auto Populate Listview with SQLite Records
« Reply #10 on: October 08, 2018, 06:09:33 PM »

Hello Bern,

Quote
I am using SQLitening in conjunction with a grid control (Farpoint's Spread).  I usually add a hidden column or two for each row to save the rowID (and possibly other data) when populating the grid control with data.  When any of the data is edited, it's easy to look up the corresponding rowID and update the database.

Thank you for your response. I use the RowID trick with the Listview. I guess it would work with MLG as well. Listview and MLG implementations are so very different. Trying to wrap my head around MLG. So far so good.

I am currently trying read the cell contents of MLG into individual Textboxes.
Logged
Fredrick O. Ughimi

fughimi@yahoo.com
- Freedom lies in being bold -- Robert Frost, Poet

cj

  • Master Geek
  • ****
  • Posts: 696
    • View Profile
Re: Auto Populate Listview with SQLite Records
« Reply #11 on: October 09, 2018, 10:42:14 AM »

If you don't mind using .NET or VB6 here are 2 great grids.

1. PowerBASIC code can be put into a DLL and loaded from VB6.
2. PowerBASIC code can use IPC (inner process communications) to talk between programs.
https://10tec.com/activex-grid  (many, features for grouping, etc.)  2  32-bit OCX's
http://grid2000.com (lot of features, but less samples)           1 32-bit OCX

I have Spread 7 somewhere and used it a long time ago.
I checked the current price at GrapeCity and about fell over.
Logged
CJ

Fredrick Ughimi

  • Master Geek
  • ****
  • Posts: 601
    • View Profile
    • Software Development Company
Re: Auto Populate Listview with SQLite Records
« Reply #12 on: October 09, 2018, 01:15:59 PM »

Hello CJ,

Thank you once a again for your response and suggestions.

Quote
I am currently trying read the cell contents of MLG into individual Textboxes.

I do that all the time with Listview. I do that mostly for the purpose of editing
and saving back changes to the database through the textboxes. I guess
I don't have to do that anymore with the Grid control. Users can edit the cells of a
row directly on the grid and then save back to the database.

Saving a row to the database is now something I need to find out.

Best regards.
Logged
Fredrick O. Ughimi

fughimi@yahoo.com
- Freedom lies in being bold -- Robert Frost, Poet