Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Listview with checkboxes

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

  • Listview with checkboxes

    ' Hi Fellows,
    '
    ' Semen Matusovski informed me about this useful feature. I have tried
    ' to implement it in virtual listviews, until now without real success.
    ' So this program is just a classic listview with the checkbox feature.
    ' One of you may be able to figure out how it could be implemented in
    ' the virtual listview with fonts and colors. If you do, please let me
    ' know.
    '
    ' Best wishes,
    '
    ' Erik Christensen, Copenhagen, Denmark ----- e.chr@email.dk
    '
    ' P.S. Be sure to have the latest version of the COMMCTRL.INC file.
    Code:
    #COMPILE EXE
    #REGISTER NONE
    #DIM ALL
    '
     %NOANIMATE    = 1
     %NOBUTTON     = 1
     %NOCOMBO      = 1
     %NODRAGLIST   = 1
     %NOHEADER     = 1
     %NOIMAGELIST  = 1
     %NOLIST       = 1
     '%NOLISTVIEW   = 1
     %NOSTATUSBAR  = 1
     %NOTABCONTROL = 1
     %NOTOOLBAR    = 1
     %NOTOOLTIPS   = 1
     %NOTRACKBAR   = 1
     %NOTREEVIEW   = 1
     %NOUPDOWN     = 1
    '
    #INCLUDE "win32api.inc"
    #INCLUDE "commctrl.inc"
    '
    %FORM1_LISTVIEW           = 100
    %FORM1_EXIT               = 102
    %FORM1_GETCHECKEDITEMS    = 105
    '
    DECLARE SUB ShowDialog_Form1(BYVAL hParent&)
    DECLARE CALLBACK FUNCTION CBF_FORM1_EXIT()
    DECLARE CALLBACK FUNCTION CBF_FORM1_GETCHECKEDITEMS()
    '
    GLOBAL hForm1&
    '
    FUNCTION PBMAIN
        LOCAL Count&
        LOCAL CC1 AS INIT_COMMON_CONTROLSEX
        CC1.dwSize=SIZEOF(CC1)
        CC1.dwICC=%ICC_WIN95_CLASSES
        InitCommonControlsEX CC1
        ShowDialog_Form1 0
        DO
            DIALOG DOEVENTS TO Count&
        LOOP UNTIL Count&=0
    END FUNCTION
    '
    SUB ShowDialog_Form1(BYVAL hParent&)
        LOCAL Style&, ExStyle&
        LOCAL hListView AS LONG,lStyle AS LONG
        LOCAL i AS LONG, j AS LONG, zText AS ASCIIZ * 100
        LOCAL lvc AS LV_COLUMN
        LOCAL lvi AS LV_ITEM
        Style& = %WS_POPUP OR %DS_MODALFRAME OR %WS_CAPTION OR %WS_MINIMIZEBOX OR %WS_SYSMENU OR %DS_CENTER
        ExStyle& = 0
        DIALOG NEW hParent&, "ListView With Checkboxes", 0, 0,  376,  224, Style&, ExStyle& TO hForm1&
        CONTROL ADD "SysListView32", hForm1&,  %FORM1_LISTVIEW,"", 8, 8, 360, 186, _
            %WS_CHILD OR %WS_VISIBLE OR %WS_BORDER OR %WS_TABSTOP OR %LVS_REPORT , _
            %WS_EX_CLIENTEDGE
        CONTROL HANDLE hForm1&,%FORM1_LISTVIEW TO hListView
        lStyle = SendMessage(hListView,%LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0)
        lStyle = lStyle OR %LVS_EX_GRIDLINES OR %LVS_EX_FULLROWSELECT OR %LVS_EX_CHECKBOXES
        CALL SendMessage(hListView, %LVM_SETEXTENDEDLISTVIEWSTYLE,0,BYVAL lStyle)
        lvc.mask = %LVCF_FMT OR %LVCF_WIDTH OR %LVCF_TEXT OR %LVCF_SUBITEM
        lvc.fmt = %LVCFMT_LEFT
        '
        %NumRows=100
        %NumCols=10
        '
        ' Define columns
        lvc.cx = 140
        lvc.cchTextMax = SIZEOF(zText)
        lvc.pszText = VARPTR(zText)
        FOR i = 1 TO %NumCols
            zText = "Column" + STR$(i)
            SendMessage hListView, %LVM_INSERTCOLUMN, i, VARPTR(lvc)
        NEXT
        '
        ' Fill listview with data
        lvi.mask = %LVIF_TEXT
        lvi.pszText = VARPTR(zText)
        FOR i = 1 TO %NumRows
            lvi.iItem = i - 1
            FOR j = 1 TO %NumCols
                zText = " row"+STR$(i)+" column"+STR$(j)
                lvi.iSubItem = j - 1
                IF j = 1 THEN ListView_InsertItem hListView, lvi ELSE ListView_SetItem hListView, lvi
            NEXT
        NEXT
        ' Check items 3 and 7 (subtract 1 since listview use base zero as the starting value)
        ListView_SetCheckState hListView , 2, 1
        ListView_SetCheckState hListView , 6, 1
        '
        CONTROL ADD "Button", hForm1&,  %FORM1_EXIT,  "E&xit", 328, 204, 40, 12, _
            %WS_CHILD OR %WS_VISIBLE OR %BS_PUSHBUTTON OR %WS_TABSTOP CALL CBF_FORM1_EXIT
        CONTROL ADD "Button", hForm1&,  %FORM1_GETCHECKEDITEMS,  "&Get Checked Item Numbers", 120, 204, 142, 12, _
            %WS_CHILD OR %WS_VISIBLE OR %BS_PUSHBUTTON OR %WS_TABSTOP CALL CBF_FORM1_GETCHECKEDITEMS
        DIALOG SHOW MODELESS hForm1&
    END SUB
    '
    CALLBACK FUNCTION CBF_FORM1_EXIT
        DIALOG END hForm1&
    END FUNCTION
    '
    CALLBACK FUNCTION CBF_FORM1_GETCHECKEDITEMS
        LOCAL t AS STRING, i AS LONG, hListView AS LONG
        CONTROL HANDLE hForm1&,%FORM1_LISTVIEW TO hListView
        FOR i=1 TO %NumRows
            IF ListView_GetCheckState (hListView, i - 1) THEN
                t=t+"  "+STR$(i)
            END IF
        NEXT
        MSGBOX t,%MB_ICONINFORMATION,"You checked the following items:"
    END FUNCTION

    ------------------


    [This message has been edited by Erik Christensen (edited December 02, 2001).]
Working...
X