Announcement

Collapse
No announcement yet.

AutoSize Column in OwnerDraw ListView

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

  • #21
    Having the same problem using gbs 00988 Virtual Listview
    ListView Fit Header will autosize the first page.
    Watching the columns resize isnt' good.

    Also, is there a way to reuse the same listview if the number of columns changes?
    I kill the listview each time a new recordset is created using Sqlite (different number of columns.)


    '
    Code:
    #PBFORMS CREATED V2.01
    #COMPILE EXE
    #DIM ALL
    #OPTION ANSIAPI 'required!!
    GLOBAL ghDlg, ghListView AS DWORD, gsArray() AS STRING
    #INCLUDE ONCE "SQLITENING.INC"
    #PBFORMS BEGIN INCLUDES
    #RESOURCE "LV.pbr"
    #INCLUDE ONCE "WIN32API.INC"
    #INCLUDE ONCE "COMMCTRL.INC"
    #INCLUDE ONCE "PBForms.INC"
    #PBFORMS END INCLUDES
    #PBFORMS BEGIN CONSTANTS
    %LISTVIEW1   =  500
    %MNU_RUN     = 1000
    #PBFORMS END CONSTANTS
    #PBFORMS DECLARATIONS
    
    FUNCTION PBMAIN()
      PBFormsInitComCtls (%ICC_WIN95_CLASSES OR %ICC_DATE_CLASSES OR %ICC_INTERNET_CLASSES)
     ShowDialog1 %HWND_DESKTOP
    END FUNCTION
    
    CALLBACK FUNCTION CBProc()
      LOCAL COL, ROW AS LONG, pLVDI AS LV_DISPINFO PTR
      SELECT CASE AS LONG CB.MSG
        CASE %WM_NCACTIVATE
          STATIC hWndSaveFocus AS DWORD
          IF ISFALSE CB.WPARAM THEN
            hWndSaveFocus = GetFocus()
          ELSEIF hWndSaveFocus THEN
            SetFocus(hWndSaveFocus)
            hWndSaveFocus = 0
          END IF
        CASE %WM_INITDIALOG
          ghDlg = CB.HNDL
        CASE %WM_NOTIFY
         SELECT CASE CB.NMID
          CASE %ListView1
           SELECT CASE CB.NMCODE
            CASE %LVN_GETDISPINFO            '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)
             @pLVDI.item.pszText = STRPTR(gsArray(COL+1,ROW+1)) 'text sent to ListView (reverse col,row)
           END SELECT
         END SELECT
    
        CASE %WM_COMMAND
          SELECT CASE AS LONG CB.CTL
            CASE %MNU_RUN
              Viewer "select rowid,* from parts order by rowid"   'THIS WOULD CONTINUALLY CHANGE
    
            CASE %LISTVIEW1
          END SELECT
      END SELECT
    END FUNCTION
    
    FUNCTION Viewer(sql AS STRING) AS LONG
     LOCAL c,cols,rows AS LONG
     IF slIsOpen = 0 THEN slOpen "sample.db3"
    
     slSelAry sql,gsArray()
     cols = UBOUND(gsArray,1)
     rows = UBOUND(gsArray,2)
     IF rows<1 THEN BEEP:EXIT FUNCTION
    
     CONTROL KILL ghDlg,%ListView1
     Closehandle ghListview
     CONTROL ADD LISTVIEW, ghDlg, %ListView1,"", 10,10,980,380, %WS_CHILD OR %WS_TABSTOP OR %WS_VISIBLE OR %LVS_SHOWSELALWAYS OR %LVS_REPORT OR %LVS_OWNERDATA OR %LVS_SHOWSELALWAYS OR %LVS_SINGLESEL
     LISTVIEW SET STYLEXX ghDlg, %ListView1, %LVS_EX_CHECKBOXES
     CONTROL HANDLE ghDlg, %ListView1 TO ghListView  'handle to ListView
     LISTVIEW SET STYLEXX ghDlg, %ListView1, %LVS_EX_CHECKBOXES
    
     'ListView Reset ghDlg,%ListView1
     FOR c = 1 TO cols
      LISTVIEW INSERT COLUMN ghDlg, %Listview1, c, "", 100,0  'set headers
      LISTVIEW SET HEADER ghDlg, %Listview1, c, gsArray(c,0)  'set headers
     NEXT
     ListView_SetItemCountEx(ghListView,rows, %LVSICF_noInvalidateAll) 'max rows
     SendMessage (ghListView, %WM_NOTIFYFORMAT, ghDlg, %NF_REQUERY)
    
      'Auto size columns.
      FOR c = 1 TO cols
        LISTVIEW FIT HEADER ghDlg, %ListView1, c
      NEXT lCol
    
    
    END FUNCTION
    
    '------------------------------------------------------------------------------
    FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
      LOCAL lRslt AS LONG
    #PBFORMS BEGIN DIALOG %IDD_DIALOG1->%IDR_MENU1->
      LOCAL hDlg  AS DWORD
    
      DIALOG NEW PIXELS, hParent, "Virtual SQLite ListView", 201, 384, 1000, 506, _
        %WS_SYSMENU OR %WS_VISIBLE OR %DS_3DLOOK OR %DS_NOFAILCREATE OR _
        %DS_SETFONT, %WS_EX_LEFT OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR _
        OR %WS_EX_CONTROLPARENT, TO hDlg
    
      AttachMENU1 hDlg
    #PBFORMS END DIALOG
     DIALOG SHOW MODAL hDlg, CALL CBProc TO lRslt
     FUNCTION = lRslt
    END FUNCTION
    '------------------------------------------------------------------------------
    FUNCTION AttachMENU1(BYVAL hDlg AS DWORD) AS DWORD
    #PBFORMS BEGIN MENU %IDR_MENU1->%IDD_DIALOG1
      LOCAL hMenu   AS DWORD
      MENU NEW BAR TO hMenu
      MENU ADD STRING, hMenu, "&Run", %MNU_RUN, %MF_ENABLED
      MENU ATTACH hMenu, hDlg
    #PBFORMS END MENU
      FUNCTION = hMenu
    END FUNCTION'gbs_00988 'Date: 03-10-2012
    '
    How long is an idea? Write it down.

    Comment


    • #22
      Howdy, Mike!


      Also, is there a way to reuse the same listview if the number of columns changes?
      Do you mean something like ListView Insert Column and ListView Delete Column?

      Comment


      • #23
        And, Mike,

        Watching the columns resize isnt' good.
        You are referring to how the columns seem to individually resize, making the screen wiggle all over the place?

        Comment


        • #24
          Gary,

          Yes, doing a hoola hoop. Thought there might be a way to do this in the callback without a timer?
          I see you went through this 6-years ago.
          How long is an idea? Write it down.

          Comment

          Working...
          X