Announcement

Collapse
No announcement yet.

Convert listview program to virtual listview

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

  • Convert listview program to virtual listview

    Hi

    How do I convert a listview program to a virtual listview?
    For example, using the sample program listed below :



    '====================================================================
    '
    ' ListView.bas example for PowerBASIC for Windows
    ' Copyright (c) 2009 - 2011 PowerBASIC, Inc.
    ' All Rights Reserved.
    '
    ' Example of using a subitems in a ListView control
    ' Also see the \Samples\DDT\Toolbar for another ListView
    ' sample application.
    '
    '====================================================================

    #COMPILER PBWIN 10
    #COMPILE EXE
    #DIM ALL

    ' Add the XP Manifest resrouce file
    #RESOURCE MANIFEST, 1, "XPTheme.xml"

    #INCLUDE ONCE "win32api.inc"

    ' Old Listview callback procedure pointer
    GLOBAL OldLVProc AS LONG

    %LVROWS = 200 ' Number of rows in the ListView
    %LVCOLS = 3 ' Number of columns in the ListView

    %ID_LABEL = 1000 ' Id of the label control
    %ID_LISTVIEW = 1001 ' id of the ListView control

    ' Application main entry point
    FUNCTION PBMAIN () AS LONG
    LOCAL hDlg AS LONG ' Handle to the dialog
    LOCAL i AS LONG ' Column counter variable
    LOCAL j AS LONG ' Row counter variable

    DIALOG NEW 0, "ListView Subitem Example", , , 314, 215, _
    %WS_POPUP OR %WS_BORDER OR %WS_DLGFRAME OR %WS_CAPTION OR _
    %WS_SYSMENU OR %WS_MINIMIZEBOX OR %WS_CLIPSIBLINGS OR %WS_VISIBLE _
    OR %DS_MODALFRAME OR %DS_3DLOOK OR %DS_NOFAILCREATE OR %DS_SETFONT, _
    %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR _
    %WS_EX_RIGHTSCROLLBAR, TO hDlg

    CONTROL ADD LABEL, hDlg, %ID_LABEL, _
    "Use the Mouse, Arrow keys, PgUp, PgDn, Home, and End keys to navigate the ListView.", _
    1, 1, 313, 8, %SS_CENTER
    CONTROL SET COLOR hDlg, %ID_LABEL, %RGB_FIREBRICK, -1

    CONTROL ADD LISTVIEW, hDlg, %ID_LISTVIEW, "", 1, 14, 312, 200, _
    %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %LVS_REPORT OR %LVS_SHOWSELALWAYS OR %LVS_SINGLESEL

    ' Add some sample text to the ListView
    FOR i= 1 TO %LVCOLS
    LISTVIEW INSERT COLUMN hDlg, %ID_LISTVIEW, i, "Column #"+FORMAT$(i), 100, 0
    NEXT i

    FOR i=1 TO %LVROWS
    LISTVIEW INSERT ITEM hDlg, %ID_LISTVIEW, i, 0, "Row #"+FORMAT$(i, "000")+" Item #01"
    FOR j = 2 TO %LVCOLS
    LISTVIEW SET TEXT hDlg, %ID_LISTVIEW, i, j, "Row #"+FORMAT$(i, "000")+" Item #"+FORMAT$(j, "00")
    NEXT j
    NEXT i

    DIALOG SHOW MODAL hDlg, CALL DlgProc
    END FUNCTION

    ' Dialog box callback procedure
    CALLBACK FUNCTION DlgProc

    SELECT CASE AS LONG CB.MSG
    CASE %WM_INITDIALOG
    ' Subclass the listview control so we can receive %WM_LButtonDown and %WM_KeyDown messages
    OldLVProc = SetWindowLongW(GetDlgItem(CB.HNDL, %ID_LISTVIEW), %GWL_WNDPROC, BYVAL CODEPTR(LVProc))

    CASE %WM_DESTROY
    ' Restore the listview controls original callback procedure
    SetWindowLongW(GetDlgItem(CB.HNDL, %ID_LISTVIEW), %GWL_WNDPROC, OldLVProc)

    END SELECT
    END FUNCTION

    ' ListView callback procedure
    FUNCTION LVProc(BYVAL hWnd AS LONG, BYVAL wMsg AS LONG, BYVAL wParam AS LONG, BYVAL lParam AS LONG) AS LONG
    STATIC COL AS LONG ' Selected column
    STATIC ROW AS LONG ' Selected row
    LOCAL c AS LONG ' Number of rows per page
    LOCAL LVHT AS LVHITTESTINFO ' Contains information about a mouse clik on the ListView

    SELECT CASE AS LONG wMsg

    CASE %WM_LBUTTONDOWN
    lvht.pt.x = LO(WORD, lparam) ' X coordinate of mouse left button down
    lvht.pt.y = HI(WORD, lparam) ' Y coordinate of mouse left button down

    ' Find the listview item and subitem at these X, Y coordinates
    SendMessageW(hwnd, %LVM_SUBITEMHITTEST, BYVAL 0, BYVAL VARPTR(LVHT))

    ' Did we find a listview item at these coordinates?
    IF lVHT.iItem <> -1 THEN
    ' Update the ListView with the new selection
    UpdateLVSelect(GetParent(hWnd), ROW, COL, lVHT.iItem+1 , LVHT.iSubItem+1)
    END IF

    ' We handled this message, so we need to return a zero
    ' and not call the the original listview callback.
    FUNCTION = 0
    EXIT FUNCTION

    CASE %WM_KEYDOWN
    SELECT CASE AS LONG wParam

    CASE %VK_UP
    ' Update the ListView with the new selection
    UpdateLVSelect(GetParent(hWnd), ROW, COL, ROW-1, COL)

    CASE %VK_DOWN
    ' Update the ListView with the new selection
    UpdateLVSelect(GetParent(hWnd), ROW, COL, ROW+1, COL)

    CASE %VK_RIGHT
    ' Update the ListView with the new selection
    UpdateLVSelect(GetParent(hWnd), ROW, COL, ROW, COL+1)

    CASE %VK_LEFT
    ' Update the ListView with the new selection
    UpdateLVSelect(GetParent(hWnd), ROW, COL, ROW, COL-1)

    CASE %VK_PGUP
    ' Get the number of rows per page in the ListView
    c = SendMessageW(hWnd, %LVM_GETCOUNTPERPAGE, 0, 0)
    ' Update the ListView with the new selection
    UpdateLVSelect(GetParent(hWnd), ROW, COL, ROW-c, COL)

    CASE %VK_PGDN
    ' Get the number of rows per page in the ListView
    c = SendMessageW(hWnd, %LVM_GETCOUNTPERPAGE, 0, 0)
    ' Update the ListView with the new selection
    UpdateLVSelect(GetParent(hWnd), ROW, COL, ROW+c, COL)

    CASE %VK_HOME
    ' Update the ListView with the new selection
    UpdateLVSelect(GetParent(hWnd), ROW, COL, 1, 1)

    CASE %VK_END
    ' Update the ListView with the new selection
    UpdateLVSelect(GetParent(hWnd), ROW, COL, %LVROWS, 1)

    END SELECT

    ' We handled this message, so we need to return a zero
    ' and not call the the original listview callback.
    FUNCTION = 0
    EXIT FUNCTION

    END SELECT

    ' if we did not handle this message, pass the message on to the
    ' original callback for the listview control.
    FUNCTION = CallWindowProcW(OldLVProc, hWnd, wMsg, wParam, lParam)
    END FUNCTION

    ' Unselect the previous listview selection, select the new item and then ensure the new
    ' item is visible.
    SUB UpdateLVSelect(BYVAL hDlg AS LONG, BYREF ROW AS LONG, BYREF COL AS LONG, BYVAL NewRow AS LONG, BYVAL NewCol AS LONG)

    ' Make sure the new row is within range
    IF NewRow < 1 THEN
    NewRow = 1
    ELSEIF NewRow > %LVROWS THEN
    NewRow = %LVROWS
    END IF

    ' Make sure the new column is within range
    IF NewCol < 1 THEN
    NewCol = 1
    ELSEIF NewCol > %LVCOLS THEN
    NewCol = %LVCOLS
    END IF

    ' If the previous and new selection are the same then do nothing
    IF (ROW = NewRow) AND (COL = NewCol) THEN EXIT SUB

    ' Unselect the previous selection, required when seleting subitems
    ' even if the ListView contains the %LVS_SINGLESEL style
    LISTVIEW UNSELECT hDlg, %ID_LISTVIEW, ROW, COL

    ' Update the Row and Column variables
    ROW = NewRow
    COL = NewCol

    ' Select the new ListView item
    LISTVIEW SELECT hDlg, %ID_LISTVIEW, ROW, COL

    ' Ensure the new ListView item is visible
    LISTVIEW VISIBLE hDlg, %ID_LISTVIEW, ROW
    END SUB

  • #2
    Welcome Tim!

    If you post (repost?) your source code enclosed bethween [CODE] and [<slash character>CODE] tags, your indentation will be preserved. You did have indentation, didn't you?

    Comment


    • #3
      Originally posted by Chris Holbrook View Post
      Welcome Tim!

      If you post (repost?) your source code enclosed bethween [CODE] and [<slash character>CODE] tags, your indentation will be preserved. You did have indentation, didn't you?
      Or use Alt+C (Edit - Copy as BB Code) in PBEdit and then paste here.

      Comment


      • #4
        Tim,
        To get a quick idea, follow "Tim 01" to "Tim 05 Tim08" in code
        As Chris said, you could put [code] in front of code and [/code] at the end

        Code:
         '====================================================================
         '
         ' ListView.bas example for PowerBASIC for Windows
         ' Copyright(c)2009 - 2011 PowerBASIC, Inc.
         ' All Rights Reserved.
         '
         ' Example of using a subitems in a ListView control
         ' Also see the \ Samples \ DDT \ Toolbar for another ListView
         ' sample application.
         '
         '====================================================================
        
        #COMPILE EXE
        #DIM ALL
        
        'Add the XP Manifest resrouce file
        #RESOURCE MANIFEST, 1, "XpTheme.xml"
        '#RESOURCE ".pbr"
        
        #INCLUDE "Win32Api.inc"
        
        'Old Listview callback procedure pointer
        GLOBAL OldLVProc AS LONG
        
        %LVROWS      = 200  'Number of rows in the ListView
        %LVCOLS      = 3    'Number of columns in the ListView
        %ID_LABEL    = 1000 'Id of the label control
        %ID_LISTVIEW = 1001 'id of the ListView control
        
        'Application main entry point
        '_______________________________________________________________________________
        
        FUNCTION PBMAIN()AS LONG
         LOCAL hDlg AS DWORD 'Handle to the dialog
         LOCAL i    AS LONG  'Column counter variable
         LOCAL j    AS LONG  'Row counter variable
        
         DIALOG NEW %HWND_DESKTOP, "ListView Subitem Example", , , 314, 215, _
         %WS_POPUP OR %WS_BORDER OR %WS_DLGFRAME OR %WS_CAPTION OR _
         %WS_SYSMENU OR %WS_MINIMIZEBOX OR %WS_CLIPSIBLINGS OR %WS_VISIBLE OR _
         %DS_MODALFRAME OR %DS_3DLOOK OR %DS_NOFAILCREATE OR %DS_SETFONT, _
         %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR _
         %WS_EX_RIGHTSCROLLBAR TO hDlg
        
         CONTROL ADD LABEL, hDlg, %ID_LABEL, _
         "Use the Mouse, Arrow keys, PgUp, PgDn, Home, and End keys to navigate the ListView.", _
         1, 1, 313, 8, %SS_CENTER
         CONTROL SET COLOR hDlg, %ID_LABEL, %RGB_FIREBRICK, - 1
        
         'Tim 01: First change the style to OR %LVS_OWNERDATA.
         'Now we will have to show where ise the data to the listview
         CONTROL ADD LISTVIEW, hDlg, %ID_LISTVIEW, "", 1, 14, 312, 200, _
         %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %LVS_REPORT OR _
         %LVS_SHOWSELALWAYS OR %LVS_SINGLESEL OR %LVS_OWNERDATA '<<<<<<<<<<<<<<<< Added LVS_OWNERDATA
        
         'Add some sample text to the ListView
         FOR i = 1 TO %LVCOLS
           LISTVIEW INSERT COLUMN hDlg, %ID_LISTVIEW, i, "Column #" + FORMAT$(i), 100, 0
         NEXT i
        
         'Tim 02: No LISTVIEW INSERT/SET because the data won't be in the listview but in our array
         'FOR i = 1 TO %LVROWS
         ' LISTVIEW INSERT ITEM hDlg, %ID_LISTVIEW, i, 0, "Row #" + FORMAT$(i, "000") + " Item #01"
         ' FOR j = 2 TO %LVCOLS
         '   LISTVIEW SET TEXT hDlg, %ID_LISTVIEW, i, j, "Row #" + FORMAT$(i, "000") + " Item #" + FORMAT$(j, "00")
         ' NEXT j
         'NEXT i
        
         'Tim 03: Build some data in a global array
         DIM sData(1 TO %LVROWS, 1 TO %LVROWS) AS GLOBAL STRING
         FOR j = 1 TO %LVROWS
           FOR i = 1 TO %LVCOLS
             sData(j, i) = UCODE$("Row #" & FORMAT$(j,"000") & " Item #" + FORMAT$(j))
           NEXT
         NEXT
        
         'Tim 04: Tell the listview how many item it have to manage
         LISTVIEW_SETITEMCOUNT(GetDlgItem(hDlg, %ID_LISTVIEW), %LVROWS)
        
         DIALOG SHOW MODAL hDlg, CALL DlgProc
        
        END FUNCTION
        '_______________________________________________________________________________
        
        CALLBACK FUNCTION DlgProc 'Dialog box callback procedure
        
         SELECT CASE AS LONG CB.MSG
        
           CASE %WM_INITDIALOG
             'Subclass the listview control so we can receive %WM_LButtonDown and %WM_KeyDown messages
             OldLVProc = SetWindowLongW(GetDlgItem(CB.HNDL, %ID_LISTVIEW), %GWL_WNDPROC, BYVAL CODEPTR(LVProc))
        
           CASE %WM_NOTIFY
             LOCAL nmLvPtr AS NM_LISTVIEW POINTER
             nmLvPtr = CBLPARAM
             SELECT CASE @nmLvPtr.hdr.idFrom 'SELECT CASE CBNMID
               CASE %ID_LISTVIEW
                 SELECT CASE @nmLvPtr.hdr.Code 'SELECT CASE CBNMCODE
        
                   CASE %LVN_GETDISPINFO, %LVN_GETDISPINFOW
                     LOCAL pLVDI AS LV_DISPINFO POINTER
                     pLVDI = CBLPARAM
                     'Tim 05: Every time the listview want to show data on screen, it have to ask where to take it
                     @pLVDI.item.pszText = STRPTR(sData(@pLVDI.item.iItem + 1, @pLVDI.item.iSubItem + 1))
        
                   'Tim 06: LVN_ITEMCHANGED section added
                   CASE %LVN_ITEMCHANGED 'turns off row selection
                     STATIC ROW AS LONG
                     STATIC COL AS LONG
                     nmLvPtr = CBLPARAM
                     LISTVIEW_SETITEMSTATE(GetDlgItem(CBHNDL, %ID_LISTVIEW), @nmLvPtr.iItem, 0, %LVIS_Focused OR %LVIS_Selected)
                     ROW = @nmLvPtr.iItem
                     LOCAL LVHT AS LVHITTESTINFO
                     LOCAL pt   AS POINTAPI
                     GetCursorPos(lvht.pt) 'Get mouse position
                     ScreenToClient(CB.HNDL, lvht.pt)
                     SendMessageW(GetDlgItem(CB.HNDL, %ID_LISTVIEW), %LVM_SUBITEMHITTEST, BYVAL 0, BYVAL VARPTR(LVHT)) 'Get column under mouse
                     COL = LVHT.iSubItem
        
                   'Tim 07: NM_CUSTOMDRAW section added
                   CASE %NM_CUSTOMDRAW 'Sets the selected cell colors
                     LOCAL lplvcd AS NMLVCUSTOMDRAW POINTER
                     lpLvCd = CBLPARAM
                     SELECT CASE @lplvcd.nmcd.dwDrawStage
        
                       CASE %CDDS_PREPAINT
                         FUNCTION = %CDRF_NOTIFYITEMDRAW
        
                       CASE %CDDS_ITEMPREPAINT
                         FUNCTION = %CDRF_NOTIFYSUBITEMDRAW
        
                       CASE %CDDS_ITEMPREPAINT OR %CDDS_SUBITEM
                         IF @lplvcd.nmcd.dwItemSpec = ROW AND @lpLvCd.iSubItem = COL THEN
                           @lpLvCd.clrTextBk = GetSysColor(%COLOR_HIGHLIGHT)
                           @lpLvCd.clrText   = GetSysColor(%COLOR_HIGHLIGHTTEXT)
                         ELSE
                           @lpLvCd.clrTextBk = GetSysColor(%COLOR_WINDOW)
                           @lpLvCd.clrText   = GetSysColor(%COLOR_WINDOWTEXT)
                         END IF
                         FUNCTION = %CDRF_NEWFONT
        
                     END SELECT
        
                END SELECT
            END SELECT
        
          CASE %WM_DESTROY
            'Restore the listview controls original callback procedure
            SetWindowLongW(GetDlgItem(CB.HNDL, %ID_LISTVIEW), %GWL_WNDPROC, OldLVProc)
        END SELECT
        END FUNCTION
        '_______________________________________________________________________________
        
        'ListView callback procedure
        FUNCTION LVProc(BYVAL hWnd AS LONG, BYVAL wMsg AS LONG, BYVAL wParam AS LONG, BYVAL lParam AS LONG)AS LONG
         STATIC COL AS LONG 'Selected column
         STATIC ROW AS LONG 'Selected row
         LOCAL c AS LONG 'Number of rows per page
         LOCAL LVHT AS LVHITTESTINFO 'Contains information about a mouse clik on the ListView
        
         SELECT CASE AS LONG wMsg
        
           CASE %WM_LBUTTONDOWN
             lvht.pt.x = LO(WORD, lparam)'X coordinate of mouse left button down
             lvht.pt.y = HI(WORD, lparam)'Y coordinate of mouse left button down
             'Find the listview item and subitem at these X, Y coordinates
             SendMessageW(hwnd, %LVM_SUBITEMHITTEST, BYVAL 0, BYVAL VARPTR(LVHT))
             'Did we find a listview item at these coordinates?
             IF lVHT.iItem<> - 1 THEN
               'Update the ListView with the new selection
               UpdateLVSelect(GetParent(hWnd), ROW, COL, lVHT.iItem + 1, LVHT.iSubItem + 1)
             END IF
             'We handled this message, so we need to return a zero
             'and not call the the original listview callback.
             FUNCTION = 0
             EXIT FUNCTION
        
           CASE %WM_KEYDOWN
        
             SELECT CASE AS LONG wParam
        
               CASE %VK_UP
                 'Update the ListView with the new selection
                 UpdateLVSelect(GetParent(hWnd), ROW, COL, ROW - 1, COL)
               CASE %VK_DOWN
                 'Update the ListView with the new selection
                 UpdateLVSelect(GetParent(hWnd), ROW, COL, ROW + 1, COL)
        
               CASE %VK_RIGHT
                 'Update the ListView with the new selection
                 UpdateLVSelect(GetParent(hWnd), ROW, COL, ROW, COL + 1)
        
               CASE %VK_LEFT
                 'Update the ListView with the new selection
                 UpdateLVSelect(GetParent(hWnd), ROW, COL, ROW, COL - 1)
        
               CASE %VK_PGUP
                 'Get the number of rows per page in the ListView
                 c = SendMessageW(hWnd, %LVM_GETCOUNTPERPAGE, 0, 0)
                 'Update the ListView with the new selection
                 UpdateLVSelect(GetParent(hWnd), ROW, COL, ROW - c, COL)
        
               CASE %VK_PGDN
                 'Get the number of rows per page in the ListView
                 c = SendMessageW(hWnd, %LVM_GETCOUNTPERPAGE, 0, 0)
                 'Update the ListView with the new selection
                 UpdateLVSelect(GetParent(hWnd), ROW, COL, ROW + c, COL)
        
               CASE %VK_HOME
                 'Update the ListView with the new selection
                 UpdateLVSelect(GetParent(hWnd), ROW, COL, 1, 1)
        
               CASE %VK_END
                 'Update the ListView with the new selection
                 UpdateLVSelect(GetParent(hWnd), ROW, COL, %LVROWS, 1)
        
             END SELECT
             'We handled this message, so we need to return a zero
             'and not call the the original listview callback.
             FUNCTION = 0
             EXIT FUNCTION
         END SELECT
         'if we did not handle this message, pass the message on to the
         'original callback for the listview control.
         FUNCTION = CallWindowProcW(OldLVProc, hWnd, wMsg, wParam, lParam)
        END FUNCTION
        '_______________________________________________________________________________
        
        'Unselect the previous listview selection, select the new item and then ensure the new
        'item is visible.
        SUB UpdateLVSelect(BYVAL hDlg AS LONG, BYREF ROW AS LONG, BYREF COL AS LONG, BYVAL NewRow AS LONG, BYVAL NewCol AS LONG)
         'Make sure the new row is within range
         IF NewRow<1 THEN
           NewRow = 1
           ELSEIF NewRow>%LVROWS THEN
           NewRow = %LVROWS
         END IF
         'Make sure the new column is within range
         IF NewCol<1 THEN
           NewCol = 1
           ELSEIF NewCol>%LVCOLS THEN
           NewCol = %LVCOLS
         END IF
         'If the previous and new selection are the same then do nothing
         IF(ROW = NewRow)AND(COL = NewCol)THEN EXIT SUB
         'Unselect the previous selection, required when seleting subitems
         'even if the ListView contains the %LVS_SINGLESEL style
         LISTVIEW UNSELECT hDlg, %ID_LISTVIEW, ROW, COL
         'Update the Row and Column variables
         ROW = NewRow
         COL = NewCol
         'Select the new ListView item
         LISTVIEW SELECT hDlg, %ID_LISTVIEW, ROW, COL
        
         'Tim 08
         CONTROL REDRAW hDlg, %ID_LISTVIEW
        
         'Ensure the new ListView item is visible
         LISTVIEW VISIBLE hDlg, %ID_LISTVIEW, ROW
        END SUB
        '_______________________________________________________________________________
        '
        Last edited by Pierre Bellisle; 12 Sep 2018, 10:04 PM.

        Comment


        • #5
          Here's a very simple compilable Virtual Listview demo.
          Given your initial question (How do I convert a listview program to a virtual listview?) , I'd advise you to learn how the concept works before extending it to you more complex example of sub classing to custom handle keystrokes.

          Code:
          'Compilable Example:
          #COMPILE EXE
          #DIM ALL
          #INCLUDE "win32api.inc"
          
          %IDC_ListView = 500
          
          %NoOFRows = 100000
          
          GLOBAL hDlg, hListView AS DWORD, D() AS STRING   'will put ListView data in D()
          
          FUNCTION PBMAIN() AS LONG
          GetSomeData
          DIALOG NEW PIXELS, 0, "Virtual ListView", , , 250,300, %WS_SYSMENU,, TO hDlg
          CONTROL ADD LISTVIEW, hDlg, %IDC_ListView, "", 0, 0, 250,300, %WS_CHILD OR %WS_TABSTOP OR %WS_VISIBLE OR %LVS_SHOWSELALWAYS OR %LVS_REPORT OR %LVS_OWNERDATA
              CONTROL HANDLE hDlg, %IDC_ListView TO hListView                   'handle to ListView
          LISTVIEW INSERT COLUMN hDlg, %IDC_Listview, 1, "Col 1", 115,0     'set headers
          LISTVIEW INSERT COLUMN hDlg, %IDC_Listview, 2, "Col 2", 115,0     'set headers
          ListView_SetItemCountEx(hListView, %NoOFRows, %LVSICF_noInvalidateAll) 'max rows
          DIALOG SHOW MODAL hDlg, CALL CBProc
          END FUNCTION
          
          CALLBACK FUNCTION CBProc
          LOCAL COL, ROW AS LONG, pLVDI AS LV_DISPINFO PTR
              LOCAL temp$$
          SELECT CASE CB.MSG
                  CASE %WM_NOTIFY
                      SELECT CASE CB.NMID
                          CASE %IDC_ListView
          SELECT CASE CB.NMCODE
                                CASE %LVN_GetDispInfoW             'notification to ask for data
          pLVDI = CB.LPARAM               'pointer to LVDISPINFO structure for requested subitem
          ROW = @pLVDI.item.iItem         'row being asked for
          COL = @pLVDI.item.iSubItem      'sub item being asked for (columns)
          temp$$ = D(ROW,COL)
                                  @pLVDI.item.pszText = STRPTR(temp$$) 'text sent to ListView
          END SELECT
                      END SELECT
              END SELECT
          END FUNCTION
          
          SUB GetSomeData
          LOCAL i,j AS LONG
              REDIM D(%NoOFRows,1)
          FOR i = 0 TO %NoOFRows
                  D(i,0) = "Col1 - Row" + STR$(i)
          D(i,1) = "Col2 - Row" + STR$(i)
          NEXT i
          END SUB

          Comment


          • #6
            Thanks to all of you. I have noted your use of the code blocks.

            Hi Pierre, when I ran your code, I found that when I clicked any of the column 2 and 3's cells, however the highlighted cells cursor stays at column 1 ?
            This behavior is unlike the original code that I have posted in post 1.



            Comment


            • #7
              I have noted your use of the code blocks.
              When posting click the button on the right with the underlined "A", that will cause the posting tools buttons to appear (if they aren't already). When ready to place code, click "#" button. That will create code tags with cursor between them. Paste or type the BASIC code. You may also type the tags youself. Either way, make tags first, or the indentation may (likely) be lost. An alternate way is from the PB IDE "Edit" menu item.

              Cheers,
              Dale

              Comment


              • #8
                Hi Tim,
                You are right, I updated the code above to behave like in the first post.
                Now, Tim 01 to Tim 08...

                Comment


                • #9
                  Thanks for all the help , Pierre
                  That's tons of work you have done recoding it

                  Comment


                  • #10
                    Hi Tim,
                    I'm glad to help.
                    In a way, starting from an existing program added complexity to it.
                    You may have a look at some code from Gary that does pretty similar using a more direct approach.
                    Gary's Simple ListView Grid - Cell Selection

                    Comment

                    Working...
                    X