• Welcome to SQLitening Support Forum.
 

News:

Welcome to the SQLitening support forums!

Main Menu

Auto Populate Listview with SQLite Records

Started by Fredrick Ughimi, October 02, 2018, 08:19:05 PM

Previous topic - Next topic

Fredrick Ughimi

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.
Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet

cj

#1
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



#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


Fredrick Ughimi

#2
Thanks CJ.

I thought as much. Would take a look at your codes.
Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet

Fredrick Ughimi

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:


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.

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")
Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet

cj

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

Fredrick Ughimi

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.
Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet

cj

Just know that Gary Beene would have to be contacted.

Fredrick Ughimi

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.
Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet

Fredrick Ughimi

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.



Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet

Bern Ertl

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

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.
Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet

cj

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.

Fredrick Ughimi

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.
Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet