Jump to content

How to disable unchecking of checkboxes in LV during processing?


Recommended Posts

Hi!

Here's the sample code:

#include <GUIConstantsEx.au3>
#include <GUIListView.au3>
#include <ListviewConstants.au3>


Global $hGUI    = GUICreate("TEST", 300, 102, -1, -1)
Global $hGUI_LV = GUICtrlCreateListView("Column1|Column2|Column3", 1, 1, 298, 73, BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS), BitOR($LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES))
Global $hGUI_B  = GUICtrlCreateButton("START", 1, 76, 298, 25)


GUISetState(@SW_SHOW, $hGUI)


While 1
    Local $msg = GUIGetMsg(1)
    Switch $msg[1]
        Case $hGUI
            Switch $msg[0]
                Case $GUI_EVENT_CLOSE
                    Exit
                Case $hGUI_B
                    _GUICtrlListView_DeleteAllItems($hGUI_LV)
                    GUICtrlSetState($hGUI_LV, $GUI_DISABLE)
                    Local $iTmp = 0
                    For $i = 97 To 122
                        Local $sTmp = Chr($i)
                        GUICtrlCreateListViewItem($sTmp & "1|" & $sTmp & "2|" & $sTmp & "3", $hGUI_LV)
                        GUICtrlSendMsg($hGUI_LV, $LVM_ENSUREVISIBLE, $iTmp, 0)
                        Sleep(250)
                        $iTmp += 1
                    Next
                    GUICtrlSetState($hGUI_LV, $GUI_ENABLE)
            EndSwitch
    EndSwitch
WEnd

GUIDelete($hGUI)

I'm trying to disable unchecking of checkboxes in a ListView while processing.

Using '$GUI_DISABLE' works and still let's the ListView auto-scoll using 'GUICtrlSendMsg()'.

But how to avoid unchecking AND keeping the ListView manually scrollable?

'$GUI_DISABLE' disables manual scrolling... :mellow:

Anyone any ideas?

Greets,

-supersonic.

Link to comment
Share on other sites

MrCreatoR came up with this.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIListView.au3>

Global $aLV_Disabled_Items[1][2]

$hGUI = GUICreate("_GUICtrlListView_AddDisabledItem Demo", 400, 200, -1, -1)
$nListView = GUICtrlCreateListView("Column1|Column2|Column3", 10, 10, 380, 180, $LVS_SHOWSELALWAYS, BitOR($LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES))
$hListView = GUICtrlGetHandle($nListView)

$nLV_Item1 = GUICtrlCreateListViewItem("1|2|3", $nListView)
$nLV_Item2 = GUICtrlCreateListViewItem("4|5|6", $nListView)
$nLV_Item3 = GUICtrlCreateListViewItem("7|8|9", $nListView)

_GUICtrlListView_AddDisabledItem($hListView, 1)

GUIRegisterMsg($WM_NOTIFY, "__WM_NOTIFY")
GUISetState(@SW_SHOW, $hGUI)

While 1
    $nMsg = GUIGetMsg()
    
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
           Exit
    EndSwitch
WEnd

Func _GUICtrlListView_AddDisabledItem($hListView, $iItemIndex)
    $aLV_Disabled_Items[0][0] += 1
    ReDim $aLV_Disabled_Items[$aLV_Disabled_Items[0][0]+1][2]
    
    $aLV_Disabled_Items[$aLV_Disabled_Items[0][0]][0] = $hListView
    $aLV_Disabled_Items[$aLV_Disabled_Items[0][0]][1] = $iItemIndex
    
    _GUICtrlListView_SetItemState($hListView, $iItemIndex, $LVIS_CUT, $LVIS_CUT)
EndFunc

Func __WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView
    $hWndListView = $nListView
    If Not IsHWnd($nListView) Then $hWndListView = GUICtrlGetHandle($nListView)
    
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $LVN_BEGINDRAG, $LVN_ITEMCHANGING
                    Local $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
                    Local $iItem = DllStructGetData($tInfo, "Item")
                    
                    For $i = 1 To $aLV_Disabled_Items[0][0]
                        If $hWndListView = $aLV_Disabled_Items[$i][0] And $iItem = $aLV_Disabled_Items[$i][1] Then
                            Return 1
                        EndIf
                    Next
            EndSwitch
    EndSwitch
    
    Return $GUI_RUNDEFMSG
EndFunc
Edited by Volly
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...