Announcement

Collapse
No announcement yet.

How to store an editable Listview cell's data into an array and then to a file

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to store an editable Listview cell's data into an array and then to a file

    Hi Pierre

    Thank you for your Editable Listview program listed in https://forum.powerbasic.com/forum/u...932#post781932


    This Listview contains cells that are editable which are great, but I would like to store its data into an array after being edited as well as saving these array data into a file.
    How do I go about doing this? Appreciate all help

  • #2
    Why not store it in a SQLite database table in memory, save to a (SQLite datbase) file is then accomplished by just opening that file and copying table to it using ATTACH DATABASE, etc.

    Comment


    • #3
      Tim,
      As an example, add this section in the main callback loop, it will save the listview data on program exit...

      Code:
         CASE %WM_DESTROY
           LOCAL RowCount AS LONG
           LOCAL ColCount AS LONG
           LOCAL hFile    AS INTEGER
      
           RowCount = SendMessage(hListview, %LVM_GETITEMCOUNT, 0, 0)
           ColCount = SendMessage(SendMessage(hlistview, %LVM_GETHEADER, 0, 0), %HDM_GETITEMCOUNT, 0, 0)
      
           DIM sText(1 TO RowCount, 1 TO ColCount) AS STRING
      
           FOR ListviewRow = 1 TO RowCount
             FOR ListviewCol = 1 TO ColCount
               ListView_GetItemText(hListView, ListviewRow - 1, ListviewCol - 1, zText, SIZEOF(zText))
               sText(ListviewRow, ListviewCol) = zText
             NEXT
           NEXT
      
           hFile = FREEFILE
           OPEN "ListViewData.txt" FOR OUTPUT AS hFile
           FOR ListviewRow = 1 TO RowCount
             FOR ListviewCol = 1 TO ColCount
               PRINT #hFile, sText(ListviewRow, ListviewCol)
             NEXT
           NEXT
           CLOSE hFile

      Comment


      • #4
        Thanks Chris, but I don't know anything about SQLite, where can I get started learning SQLite ?

        Thanks Pierre, for your codes and that's all I needed

        Comment


        • #5
          Originally posted by Tim Lakinir View Post
          Thanks Chris, but I don't know anything about SQLite, where can I get started learning SQLite ?
          here's one of many tutorial sites: http://www.sqlitetutorial.net/

          But if you don't need it, that's even better!

          Comment


          • #6
            Thanks Chris. where can I start learning SQLite with PB ? any simple examples for beginners?

            Comment


            • #7
              The one I recently posted to the source code forum here https://forum.powerbasic.com/forum/u...ing#post783879 is probably the simplest. I’ve also done a few variations on the theme of SQLite-table-to-list-view. There are lots of examples from others too. But note that SQLite changed from version 2 to version 3 a dozen years or more ago, it was a big change and V2 stuff is probably best left alone.

              Comment

              Working...
              X