Announcement

Collapse
No announcement yet.

deselecting all rows in a Listview

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

  • Chris Holbrook
    replied
    [QUOTE=Michael Mattias;270948]but I'm not sure this works on a multi-select listview or not.
    [code]

    Yes, that's the one, included in revised code above. Thanks!

    Leave a comment:


  • Michael Mattias
    replied
    Haven't tested recently but I found this in my collection of Listview functions...but I'm not sure this works on a multi-select listview or not. Worth a try anyway..

    Code:
    ' un-select all
    FUNCTION ListView_UnselectAll (BYVAL hwnd AS LONG) AS LONG
      ListView_SetItemState hWnd, -1, BYVAL %NULL, %LVIS_SELECTED OR %LVIS_FOCUSED
    END FUNCTION

    Leave a comment:


  • Chris Holbrook
    started a topic deselecting all rows in a Listview

    deselecting all rows in a Listview

    This little program swaps multiple selections between the listview and text box. Somewhere I have seen a two-line routine to clear all the select flags without looping through the whole listview, but I can't find it, can anyone help with this please?

    ** OK I fixed it, code changed below **

    Code:
    #COMPILE EXE
    #DIM ALL
    #REGISTER ALL
    
    %USEMACROS = 1
    #INCLUDE "WIN32API.INC"
    #INCLUDE "COMMCTRL.INC"
    
    
    %IDC_LV             = 100
    %IDC_TB             = 101
    %IDC_LV2TB          = 102
    %IDC_TB2LV          = 103
    
    '------------------------------------------------------------------------------
    SUB loadListView  ( hD AS DWORD)
      LOCAL i, row, iPos AS LONG
      LOCAL lvhit AS LV_HITTESTINFO, lvi AS LV_ITEM, lvc AS LV_COLUMN
      LOCAL sz AS ASCIIZ * 1024, rc AS RECT
    
        lvi.mask    = %LVIF_TEXT
        lvi.pszText = VARPTR(sz)
        FOR i = 1 TO 1000
            sz     = "This is item number " + FORMAT$(i, "0000")
            lvi.iItem = i-1
            CONTROL SEND hD, %IDC_LV, %LVM_INSERTITEM, 0, VARPTR(lvi)
        NEXT i
        ' Set column info...
        GetClientRect GetDlgItem(hD, %IDC_LV), rc
        sz       = "Test Items"
        lvc.mask    = %LVCF_WIDTH OR %LVCF_TEXT
        lvc.pszText = VARPTR(sz)
        lvc.cx      = rc.nRight
        CONTROL SEND hD, %IDC_LV, %LVM_INSERTCOLUMN, 0, VARPTR(lvc)
    END SUB
    '------------------------------------------------------------------------------
    SUB SqueezeTB2Text ( hD AS DWORD, hC AS LONG, s AS STRING )
        LOCAL hWndTxt AS DWORD
        LOCAL rc, rcTxt1, rcTxt2 AS rect
        LOCAL NCHeight AS LONG
        'local txt as string
        LOCAL szText    AS ASCIIZ*1024
        LOCAL hDC       AS DWORD
        LOCAL hFont     AS LONG
        LOCAL nWidth    AS LONG
        LOCAL nHeight   AS LONG
        LOCAL hFontOld  AS LONG
        LOCAL x, y, xx, yy AS LONG
        
         CONTROL HANDLE hD, hC TO hWndTxt
         GetWindowRect hWndTXT, rcTxt1
         GetClientRect hWndTXT, rcTxt2
         MapWindowPoints %HWND_DESKTOP, hD, rcTxt1, 2
         MapWindowPoints %HWND_DESKTOP, hD, rcTxt2, 2
         NCHeight = (rcTxt1.nBottom-rcTxt1.nTop)-(rcTxt2.nBottom-rcTxt2.nTop)
         'CONTROL GET TEXT hD, hC TO txt
         IF s = "" THEN EXIT SUB
         szText = s
         hFont=SendMessage(hWndTXT, %WM_GETFONT, 0, 0)
         hDC=GetDC(hWndTXT)
         hFontOld=SelectObject(hDC, hFont)
         TYPE SET rc=rcTxt2
         DrawText hDC, szText, LEN(szText), rc, %DT_CALCRECT OR %DT_WORDBREAK
         SelectObject hDC, hFontOld
         ReleaseDC hWndTXT, hDC
         x=rcTxt1.nLeft
         y=rcTxt1.nTop
         xx=(rcTxt1.nRight-rcTxt1.nLeft)
         yy=(rc.nBottom-rc.nTop)+(NCHeight*2)
         MoveWindow hWndTXT, x, y, xx, yy, %TRUE
         CONTROL SET TEXT hD, hC, s
    
    END SUB
    ' Main dialog callback procedure
    '------------------------------------------------------------------------------
    CALLBACK FUNCTION dlgMain
      LOCAL LVF AS lVFindInfo
      LOCAL i, row, iPos AS LONG
      LOCAL lvhit AS LV_HITTESTINFO, lvi AS LV_ITEM, lvc AS LV_COLUMN
      LOCAL sz AS ASCIIZ * 1024, rc AS RECT
      LOCAL s AS STRING
      STATIC bDragItem AS BYTE, hListView AS DWORD
      STATIC hTBW AS LONG ' handle for text box control's window
    
      SELECT CASE CBMSG
    
             CASE %WM_INITDIALOG
                  ' Prepare example listview items...
                  LoadListView ( CBHNDL)
                  CONTROL HANDLE CBHNDL, %IDC_TB TO hTBW
                  CONTROL HANDLE CBHNDL, %IDC_LV TO hListView
             CASE %WM_COMMAND
                  IF (CBCTL = %IDC_LV2TB) AND (CBCTLMSG = %BN_CLICKED) THEN
                       i = 0
                       DO
                          i = ListView_GetNextItem(hListView,i,%LVNI_SELECTED)
                          IF i = -1 THEN
                              'CONTROL SET TEXT CBHNDL, %IDC_TB, s
                              squeezeTB2Text(CBHNDL, %IDC_TB, s)
                              FUNCTION  = 0
                              EXIT FUNCTION
                          END IF
                          Listview_GetItemText ( hListView, i, 0, sz, 1024)
                          IF s = "" THEN
                              s = sz
                          ELSE
                              s = s + "," + sz
                          END IF
                       LOOP
                  END IF
                  IF (CBCTL = %IDC_TB2LV) AND (CBCTLMSG = %BN_CLICKED) THEN
                      CONTROL GET TEXT CBHNDL, %IDC_TB TO s
                      ListView_SetItemState (hListView, -1, %NULL, %LVIS_SELECTED OR %LVIS_FOCUSED)
                      FOR i = 1 TO PARSECOUNT(s)
                           sz = PARSE$(s,i)
                           LVF.flags = %LVFI_STRING
                           LVF.psz = VARPTR(sz)
                           row = Listview_FindItem ( hListView, -1, LVF)
                           IF row <> -1 THEN
                               ListView_SetItemState (hListView, row, %LVIS_SELECTED OR %LVIS_FOCUSED, %LVIS_SELECTED OR %LVIS_FOCUSED)
                           END IF
                           CONTROL SET FOCUS CBHNDL, %IDC_LV
                      NEXT
                  END IF
      END SELECT
    
    END FUNCTION
    '------------------------------------------------------------------------------
    ' Program Start Point
    '------------------------------------------------------------------------------
    FUNCTION PBMAIN
    
      LOCAL hDlg AS DWORD
    
      DIALOG NEW 0, "ListView from and to Textbox", , , 250, 300, %DS_MODALFRAME OR %WS_CAPTION OR %WS_SYSMENU OR %WS_POPUP TO hDlg
    
      CONTROL ADD $WC_LISTVIEW, hDlg, %IDC_LV, "", 0, 0, 250, 130, %ws_child OR %WS_TABSTOP _
                                      OR %WS_VISIBLE OR %LVS_SHOWSELALWAYS OR %LVS_REPORT, %WS_EX_CLIENTEDGE
      CONTROL ADD TEXTBOX, hDlg, %IDC_TB, "", 0, 150, 250, 100, %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR _
            %ES_LEFT OR %ES_MULTILINE, %WS_EX_CLIENTEDGE OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR _
            %WS_EX_RIGHTSCROLLBAR
      CONTROL ADD BUTTON, hDlg, %IDC_LV2TB, "LV to TB", 50, 275, 50, 15
      CONTROL ADD BUTTON, hDlg, %IDC_TB2LV, "TB to LV", 150, 275, 50, 15
    
      DIALOG SHOW MODAL hDlg CALL dlgMain
    
    END FUNCTION
    Last edited by Chris Holbrook; 13 Dec 2007, 04:46 AM. Reason: correct code thereby answering own question
Working...
X