Jump to content
Sign in to follow this  
UEZ

How a ListView acts as CTRL was pressed by default?

Recommended Posts

UEZ

I want that the Listview acts as CTRL key was pressed by default to avoid any deletion when the listview was clicked.

Here an example code:

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

$hGUI = GUICreate("ListView Test", 400, 550)
$iLV = GUICtrlCreateListView("", 0, 10, 400, 480, $LVS_SHOWSELALWAYS, BitOR($LVS_EX_FLATSB, $LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER))
_GUICtrlListView_AddColumn($iLV, "Date", 100, 1)
_GUICtrlListView_AddColumn($iLV, "Size (bytes)", 100, 1)
_GUICtrlListView_AddColumn($iLV, "File Name", 100, 1)
For $i = 0 to 150
    _GUICtrlListView_AddItem($iLV, "Row " & $i)
    _GUICtrlListView_AddSubItem($iLV, $i, $i * 2, 1)
    _GUICtrlListView_AddSubItem($iLV, $i, $i * 4, 2)
Next

$cButton = GUICtrlCreateButton("Reset", 10, 510, 80, 30)

GUISetState()
_GUICtrlListView_SetItemChecked($iLV, 0)
_GUICtrlListView_SetItemSelected($iLV, 0)
_GUICtrlListView_SetItemChecked($iLV, 1)
_GUICtrlListView_SetItemSelected($iLV, 1)
_GUICtrlListView_SetItemChecked($iLV, 2)
_GUICtrlListView_SetItemSelected($iLV, 2)
ControlFocus($hGUI, "", $iLV)

; Create array to hold selection state
Global $aSelected[_GUICtrlListView_GetItemCount($iLV)]

GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cButton
            ; Clear all selections
             _GUICtrlListView_SetItemSelected($iLV, -1, False)
             ; Clear selected array
            Global $aSelected[_GUICtrlListView_GetItemCount($iLV)]
    EndSwitch
WEnd

Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $wParam

    ; Struct = $tagNMHDR and "int Item;int SubItem" from $tagNMLISTVIEW
    Local $tStruct = DllStructCreate("hwnd;uint_ptr;int_ptr;int;int", $lParam)
    If @error Then Return
    Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    Local $hWndFrom = HWnd($tNMHDR.hWndFrom)
    Local $iIDFrom = $tNMHDR.IDFrom
    Local $iCode = $tNMHDR.Code
    Local Static $iCount = 0
    Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam)
    Switch $iCode
        Case $LVN_ITEMCHANGED
            If BitAND($tInfo.Changed, $LVIF_STATE) = $LVIF_STATE Then
                Switch $tInfo.NewState
                    Case 8192 ;item checked
                        _GUICtrlListView_SetItemSelected($iLV, $tInfo.Item, True)
                    Case 4096 ;item unchecked
                        _GUICtrlListView_SetItemSelected($iLV, $tInfo.Item, False)
                EndSwitch
            EndIf
        Case $NM_CLICK
           $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
;~          _DebugPrint("$NM_CLICK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
;~                  "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
;~                  "-->Code:" & @TAB & $iCode & @CRLF & _
;~                  "-->Index:" & @TAB & $tInfo.Index & @CRLF & _
;~                  "-->SubItem:" & @TAB & $tInfo.SubItem & @CRLF & _
;~                  "-->NewState:" & @TAB & $tInfo.NewState & @CRLF & _
;~                  "-->OldState:" & @TAB & $tInfo.OldState & @CRLF & _
;~                  "-->Changed:" & @TAB & $tInfo.Changed & @CRLF & _
;~                  "-->ActionX:" & @TAB & $tInfo.ActionX & @CRLF & _
;~                  "-->ActionY:" & @TAB & $tInfo.ActionY & @CRLF & _
;~                  "-->lParam:" & @TAB & $tInfo.lParam & @CRLF & _
;~                  "-->KeyFlags:" & @TAB & $tInfo.KeyFlags)
            _GUICtrlListView_SetItemChecked($iLV, $tInfo.Index, _GUICtrlListView_GetItemState($iLV, $tInfo.Index, $LVIS_SELECTED))
    EndSwitch
    Return $__LISTVIEWCONSTANT_GUI_RUNDEFMSG
EndFunc

Func _DebugPrint($s_Text , $sLine = @ScriptLineNumber)
    ConsoleWrite( _
            "!===========================================================" & @CRLF & _
            "+======================================================" & @CRLF & _
            "-->Line(" & StringFormat("%04d", $sLine) & "):" & @TAB & $s_Text  & @CRLF & _
            "+======================================================" & @CRLF)
EndFunc   ;==>_DebugPrint

Just cklick the listview and you will see that the selection is deleted. Repeat it and hold the CTRL key pressed.

Any ideas?

I don't want to read the listview and check whether the checkbox is checked and mark the row appropriately! It's lagging...

 

Thanks,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
LarsJ

UEZ, May be you can use something like this:

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

$hGUI = GUICreate("ListView Test", 400, 550)
$iLV = GUICtrlCreateListView("", 0, 10, 400, 480, $LVS_SHOWSELALWAYS, BitOR($LVS_EX_FLATSB, $LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER))
_GUICtrlListView_AddColumn($iLV, "Date", 100, 1)
_GUICtrlListView_AddColumn($iLV, "Size (bytes)", 100, 1)
_GUICtrlListView_AddColumn($iLV, "File Name", 100, 1)
For $i = 0 to 150
    _GUICtrlListView_AddItem($iLV, "Row " & $i)
    _GUICtrlListView_AddSubItem($iLV, $i, $i * 2, 1)
    _GUICtrlListView_AddSubItem($iLV, $i, $i * 4, 2)
Next
_GUICtrlListView_SetItemChecked($iLV, 0)
_GUICtrlListView_SetItemParam($iLV, 0, True)
_GUICtrlListView_SetItemChecked($iLV, 1)
_GUICtrlListView_SetItemParam($iLV, 1, True)
_GUICtrlListView_SetItemChecked($iLV, 2)
_GUICtrlListView_SetItemParam($iLV, 2, True)
ControlFocus($hGUI, "", $iLV)

GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

GUISetState()

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

Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
  #forceref $hWnd, $iMsg, $wParam
  Local $tNMHDR, $iCode
  $tNMHDR = DllStructCreate( $tagNMHDR, $lParam )
  $iCode = $tNMHDR.Code

  Switch $iCode
    Case $LVN_ITEMCHANGED
      Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam)
      If BitAND($tInfo.Changed, $LVIF_STATE) = $LVIF_STATE Then
        Switch $tInfo.NewState
          Case 8192 ;item checked
            _GUICtrlListView_SetItemParam($iLV, $tInfo.Item, True)
          Case 4096 ;item unchecked
            _GUICtrlListView_SetItemParam($iLV, $tInfo.Item, False)
        EndSwitch
      EndIf

    Case $NM_CLICK
      Local $aInfo = GUIGetCursorInfo()
      Local $aTest = _GUICtrlListView_SubItemHitTest( $iLV, $aInfo[0], $aInfo[1] )
      If Not ( Not $aTest[4] And $aTest[6] ) Then
        $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
        Local $fChecked = Not _GUICtrlListView_GetItemParam($iLV, $tInfo.Index)
        _GUICtrlListView_SetItemParam($iLV, $tInfo.Index, $fChecked)
        _GUICtrlListView_SetItemChecked($iLV, $tInfo.Index, $fChecked)
      EndIf

    Case $NM_CUSTOMDRAW
      Local $tNMLVCUSTOMDRAW = DllStructCreate( $tagNMLVCUSTOMDRAW, $lParam )
      Local $dwDrawStage = DllStructGetData( $tNMLVCUSTOMDRAW, "dwDrawStage" )

      Switch $dwDrawStage                               ; Holds a value that specifies the drawing stage

        Case $CDDS_PREPAINT                             ; Before the paint cycle begins
          Return $CDRF_NOTIFYITEMDRAW                   ; Notify the parent window of any ITEM-related drawing operations

        Case $CDDS_ITEMPREPAINT                         ; Before painting an item
          Return $CDRF_NOTIFYSUBITEMDRAW                ; Notify the parent window of any SUBITEM-related drawing operations

        Case BitOR( $CDDS_ITEMPREPAINT, $CDDS_SUBITEM ) ; Before painting a subitem
          Local $lItemlParam = $tNMLVCUSTOMDRAW.lItemlParam ; Item param
          Local $iSubItem    = $tNMLVCUSTOMDRAW.iSubItem    ; Subitem index
          Local $uItemState  = $tNMLVCUSTOMDRAW.uItemState  ; Item state
          If $lItemlParam Then ; Checked rows
            If Not BitAnd( $uItemState, $CDIS_FOCUS ) Then
              DllStructSetData( $tNMLVCUSTOMDRAW, "ClrText",   0xFFFFFF ) ; Forecolor white
              DllStructSetData( $tNMLVCUSTOMDRAW, "clrTextBk", 0xCC6600 ) ; Backcolor dark blue, BGR
            EndIf
          Else ; Other rows
            If Not BitAnd( $uItemState, $CDIS_FOCUS ) Then
              DllStructSetData( $tNMLVCUSTOMDRAW, "ClrText",   0x000000 )
              DllStructSetData( $tNMLVCUSTOMDRAW, "ClrTextBk", 0xFFFFFF )
            EndIf
          EndIf
          Return $CDRF_NEWFONT                          ; $CDRF_NEWFONT must be returned after changing font or colors

      EndSwitch

  EndSwitch

  Return $GUI_RUNDEFMSG
EndFunc
Checked state (and selection) in ItemParam.
  • Like 1

Share this post


Link to post
Share on other sites
UEZ

LarsJ,

interesting idea to simulate the CTRL key behavior which didn't came to my mind although I used  $NM_CUSTOMDRAW to draw the grid in different color.  :thumbsup:

Just for my curiosity: is there a way without simulating? How is windows handling the lv when ctrl is pressed?

Thanks!

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
Melba23

LarsJ,

Another nice script. :thumbsup:

But could I make 2 suggested changes?

- 1. When adding extended styles to a ListView it is always advisable to use _GUICtrlListView_SetExtendedListViewStyle as some of these values are also used by $WS_Ex_* styles and can be confused with them. That is why the function exists. ;)

- 2. In ListViews created with the native function, AutoIt uses the item parameter to store the internal ControlID of the row. As explained in the Help file, it is best to use parameter values well above any possible existing ControlIDs (we recommend 1000+) as experience has shown that there can be "ghost" effects on the real control if this is not done. In this case you are only using True/False (1/0) and so there is no real possibility of this happening, but I raise it a useful hint for anyone reading. :)

Making those changes does not affect the script as you can see here (I use 1000/1001 as checked/unchecked):

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

$hGUI = GUICreate("ListView Test", 400, 550)
$iLV = GUICtrlCreateListView("", 0, 10, 400, 480, $LVS_SHOWSELALWAYS)
_GUICtrlListView_SetExtendedListViewStyle($iLV, BitOR($LVS_EX_FLATSB, $LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER))

_GUICtrlListView_AddColumn($iLV, "Date", 100, 1)
_GUICtrlListView_AddColumn($iLV, "Size (bytes)", 100, 1)
_GUICtrlListView_AddColumn($iLV, "File Name", 100, 1)
For $i = 0 To 150
    _GUICtrlListView_AddItem($iLV, "Row " & $i)
    _GUICtrlListView_SetItemParam($iLV, $i, 1000)
    _GUICtrlListView_AddSubItem($iLV, $i, $i * 2, 1)
    _GUICtrlListView_AddSubItem($iLV, $i, $i * 4, 2)
Next
_GUICtrlListView_SetItemChecked($iLV, 0)
_GUICtrlListView_SetItemParam($iLV, 0, 1001)
_GUICtrlListView_SetItemChecked($iLV, 1)
_GUICtrlListView_SetItemParam($iLV, 1, 1001)
_GUICtrlListView_SetItemChecked($iLV, 2)
_GUICtrlListView_SetItemParam($iLV, 2, 1001)
ControlFocus($hGUI, "", $iLV)

GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

GUISetState()

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

Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    Local $tNMHDR, $iCode
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $iCode = $tNMHDR.Code

    Switch $iCode
        Case $LVN_ITEMCHANGED
            Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam)
            If BitAND($tInfo.Changed, $LVIF_STATE) = $LVIF_STATE Then
                Switch $tInfo.NewState
                    Case 8192 ;item checked
                        _GUICtrlListView_SetItemParam($iLV, $tInfo.Item, 1001)
                    Case 4096 ;item unchecked
                        _GUICtrlListView_SetItemParam($iLV, $tInfo.Item, 1000)
                EndSwitch
            EndIf

        Case $NM_CLICK
            Local $aInfo = GUIGetCursorInfo()
            Local $aTest = _GUICtrlListView_SubItemHitTest($iLV, $aInfo[0], $aInfo[1])
            If Not (Not $aTest[4] And $aTest[6]) Then
                $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
                Local $iChecked = _GUICtrlListView_GetItemParam($iLV, $tInfo.Index)
                ConsoleWrite($iChecked & @CRLF)
                If $iChecked = 1000 Then
                    _GUICtrlListView_SetItemParam($iLV, $tInfo.Index, 1001)
                    _GUICtrlListView_SetItemChecked($iLV, $tInfo.Index, True)
                Else
                    _GUICtrlListView_SetItemParam($iLV, $tInfo.Index, 1000)
                    _GUICtrlListView_SetItemChecked($iLV, $tInfo.Index, False)
                EndIf

            EndIf

        Case $NM_CUSTOMDRAW
            Local $tNMLVCUSTOMDRAW = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam)
            Local $dwDrawStage = DllStructGetData($tNMLVCUSTOMDRAW, "dwDrawStage")

            Switch $dwDrawStage ; Holds a value that specifies the drawing stage

                Case $CDDS_PREPAINT ; Before the paint cycle begins
                    Return $CDRF_NOTIFYITEMDRAW ; Notify the parent window of any ITEM-related drawing operations

                Case $CDDS_ITEMPREPAINT ; Before painting an item
                    Return $CDRF_NOTIFYSUBITEMDRAW ; Notify the parent window of any SUBITEM-related drawing operations

                Case BitOR($CDDS_ITEMPREPAINT, $CDDS_SUBITEM) ; Before painting a subitem
                    Local $lItemlParam = $tNMLVCUSTOMDRAW.lItemlParam ; Item param
                    Local $iSubItem = $tNMLVCUSTOMDRAW.iSubItem ; Subitem index
                    Local $uItemState = $tNMLVCUSTOMDRAW.uItemState ; Item state
                    If $lItemlParam = 1001 Then ; Checked rows
                        If Not BitAND($uItemState, $CDIS_FOCUS) Then
                            DllStructSetData($tNMLVCUSTOMDRAW, "ClrText", 0xFFFFFF) ; Forecolor white
                            DllStructSetData($tNMLVCUSTOMDRAW, "clrTextBk", 0xCC6600) ; Backcolor dark blue, BGR
                        EndIf
                    Else ; Other rows
                        If Not BitAND($uItemState, $CDIS_FOCUS) Then
                            DllStructSetData($tNMLVCUSTOMDRAW, "ClrText", 0x000000)
                            DllStructSetData($tNMLVCUSTOMDRAW, "ClrTextBk", 0xFFFFFF)
                        EndIf
                    EndIf
                    Return $CDRF_NEWFONT ; $CDRF_NEWFONT must be returned after changing font or colors

            EndSwitch

    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_NOTIFY
M23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
UEZ

At first glance it looks like what I want BUT it doesn't work when you have checkboxes and mark checked and unmark unchecked rows in the list view.
Only rows with checked checkboxes should be selected using _GUICtrlListView_SetItemSelected().


Is it possible in this section

...
                            If $wParam = $iListView_Web Then
                                Local $lItemlParam = $tNMLVCUSTOMDRAW.lItemlParam ; Item param
                                Local $iSubItem = $tNMLVCUSTOMDRAW.iSubItem ; Subitem index
                                Local $uItemState = $tNMLVCUSTOMDRAW.uItemState ; Item state

                                If $lItemlParam Then ; Checked rows
                                    If Not BitAND($uItemState, $CDIS_FOCUS) Then
                                        DllStructSetData($tNMLVCUSTOMDRAW, "ClrText", $iColor_Text) ; Forecolor white
                                        DllStructSetData($tNMLVCUSTOMDRAW, "clrTextBk", 0x00FF00) ;0xFF9933) ; Backcolor blue, BGR
                                    EndIf
                                Else ; Other rows
                                    If Not BitAND($uItemState, $CDIS_FOCUS) Then
                                        DllStructSetData($tNMLVCUSTOMDRAW, "ClrText", $iColor_Text)
                                        DllStructSetData($tNMLVCUSTOMDRAW, "ClrTextBk", 0x0000FF) ;$iColor_LV)
                                    EndIf
                                EndIf
                            EndIf
...

to set the background color only for checked rows?


Edit: seems that $CDIS_CHECKED, $CDIS_SELECTED, $CDIS_MARKED are doing partly the job. Continuing to test and search for a solution...


Btw, is there a way to get the color which the system uses to mark a row in LV? -> _WinAPI_GetSysColor($COLOR_HIGHLIGHT)


Forget it, it was my wrong implementation which caused the problems.


Br,
UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
LarsJ

One important thing. Because a row is drawn only in one color, the row should be drawn in the item part of the drawing stage, where the entire row is drawn at once. To draw such a row column by column in the subitem part is wrong, and leads to bad performance.

Here the rows are drawn in the item part of the drawing stage. The subitem part is deleted. A controlID offset with a value of 1000 is added to ItemParam.

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

$hGUI = GUICreate("ListView Test", 400, 550)
$iLV = GUICtrlCreateListView("", 0, 10, 400, 480, $LVS_SHOWSELALWAYS, BitOR($LVS_EX_FLATSB, $LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER))
_GUICtrlListView_AddColumn($iLV, "Date", 100, 1)
_GUICtrlListView_AddColumn($iLV, "Size (bytes)", 100, 1)
_GUICtrlListView_AddColumn($iLV, "File Name", 100, 1)
For $i = 0 to 150
    _GUICtrlListView_AddItem($iLV, "Row " & $i)
    _GUICtrlListView_AddSubItem($iLV, $i, $i * 2, 1)
    _GUICtrlListView_AddSubItem($iLV, $i, $i * 4, 2)
    _GUICtrlListView_SetItemParam($iLV, $i, 1000)
Next
_GUICtrlListView_SetItemChecked($iLV, 0)
_GUICtrlListView_SetItemParam($iLV, 0, 1001)
_GUICtrlListView_SetItemChecked($iLV, 1)
_GUICtrlListView_SetItemParam($iLV, 1, 1001)
_GUICtrlListView_SetItemChecked($iLV, 2)
_GUICtrlListView_SetItemParam($iLV, 2, 1001)
ControlFocus($hGUI, "", $iLV)

GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

GUISetState()

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

Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
  #forceref $hWnd, $iMsg, $wParam
  Local $tNMHDR, $iCode
  $tNMHDR = DllStructCreate( $tagNMHDR, $lParam )
  $iCode = $tNMHDR.Code

  Switch $iCode
    Case $LVN_ITEMCHANGED
      Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam)
      If BitAND($tInfo.Changed, $LVIF_STATE) = $LVIF_STATE Then
        Switch $tInfo.NewState
          Case 8192 ;item checked
            _GUICtrlListView_SetItemParam($iLV, $tInfo.Item, 1001)
          Case 4096 ;item unchecked
            _GUICtrlListView_SetItemParam($iLV, $tInfo.Item, 1000)
        EndSwitch
      EndIf

    Case $NM_CLICK
      Local $aInfo = GUIGetCursorInfo()
      Local $aTest = _GUICtrlListView_SubItemHitTest( $iLV, $aInfo[0], $aInfo[1] )
      If Not ( Not $aTest[4] And $aTest[6] ) Then
        $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
        Local $fChecked = Not ( _GUICtrlListView_GetItemParam($iLV, $tInfo.Index) = 1001 )
        _GUICtrlListView_SetItemParam($iLV, $tInfo.Index, $fChecked + 1000)
        _GUICtrlListView_SetItemChecked($iLV, $tInfo.Index, $fChecked)
      EndIf

    Case $NM_CUSTOMDRAW
      Local $tNMLVCUSTOMDRAW = DllStructCreate( $tagNMLVCUSTOMDRAW, $lParam )
      Local $dwDrawStage = DllStructGetData( $tNMLVCUSTOMDRAW, "dwDrawStage" )

      Switch $dwDrawStage                               ; Holds a value that specifies the drawing stage

        Case $CDDS_PREPAINT                             ; Before the paint cycle begins
          Return $CDRF_NOTIFYITEMDRAW                   ; Notify the parent window of any ITEM-related drawing operations

        Case $CDDS_ITEMPREPAINT                         ; Before painting an item
          Local $lItemlParam = $tNMLVCUSTOMDRAW.lItemlParam - 1000 ; Item param
          Local $uItemState  = $tNMLVCUSTOMDRAW.uItemState         ; Item state
          If $lItemlParam Then ; Checked rows
            If Not BitAnd( $uItemState, $CDIS_FOCUS ) Then
              DllStructSetData( $tNMLVCUSTOMDRAW, "ClrText",   0xFFFFFF ) ; Forecolor white
              DllStructSetData( $tNMLVCUSTOMDRAW, "clrTextBk", 0xCC6600 ) ; Backcolor dark blue, BGR
            EndIf
          Else ; Other rows
            If Not BitAnd( $uItemState, $CDIS_FOCUS ) Then
              DllStructSetData( $tNMLVCUSTOMDRAW, "ClrText",   0x000000 )
              DllStructSetData( $tNMLVCUSTOMDRAW, "ClrTextBk", 0xFFFFFF )
            EndIf
          EndIf
          Return $CDRF_NEWFONT                          ; $CDRF_NEWFONT must be returned after changing font or colors

      EndSwitch

  EndSwitch

  Return $GUI_RUNDEFMSG
EndFunc

Share this post


Link to post
Share on other sites
UEZ

Thanks LarsJ.
 
One question how would you implement multi selection? I mean if you change $NM_CLICK to $NM_DBLCLK and select some rows by holding down the shift key. These lines should be marked and the checkbox should be set.

The same when unselecting some lines.
 

This is what I did:

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


Global Const $iColor_TextBk = _WinAPI_GetSysColor($COLOR_HIGHLIGHT)
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIListView.au3>

$hGUI = GUICreate("ListView Test", 400, 550)
$iLV = GUICtrlCreateListView("", 0, 10, 400, 480, $LVS_SHOWSELALWAYS)
_GUICtrlListView_SetExtendedListViewStyle($iLV, BitOR($LVS_EX_FLATSB, $LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER))

_GUICtrlListView_AddColumn($iLV, "Date", 100, 1)
_GUICtrlListView_AddColumn($iLV, "Size (bytes)", 100, 1)
_GUICtrlListView_AddColumn($iLV, "File Name", 100, 1)
For $i = 0 To 150
    _GUICtrlListView_AddItem($iLV, "Row " & $i)
    _GUICtrlListView_SetItemParam($iLV, $i, 1000)
    _GUICtrlListView_AddSubItem($iLV, $i, $i * 2, 1)
    _GUICtrlListView_AddSubItem($iLV, $i, $i * 4, 2)
Next
_GUICtrlListView_SetItemChecked($iLV, 0)
_GUICtrlListView_SetItemParam($iLV, 0, 1001)
_GUICtrlListView_SetItemChecked($iLV, 1)
_GUICtrlListView_SetItemParam($iLV, 1, 1001)
_GUICtrlListView_SetItemChecked($iLV, 2)
_GUICtrlListView_SetItemParam($iLV, 2, 1001)
ControlFocus($hGUI, "", $iLV)

GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

GUISetState()

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

Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    Local $tNMHDR, $iCode, $aIndices, $n
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $iCode = $tNMHDR.Code

    Switch $iCode
        Case $LVN_ITEMCHANGED
            Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam)
            If BitAND($tInfo.Changed, $LVIF_STATE) = $LVIF_STATE Then
                Switch $tInfo.NewState
                    Case 8192 ;item checked
                        _GUICtrlListView_SetItemParam($iLV, $tInfo.Item, 1001)
                    Case 4096 ;item unchecked
                        _GUICtrlListView_SetItemParam($iLV, $tInfo.Item, 1000)
                EndSwitch
            EndIf
        Case $NM_CLICK
            $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
            If $tInfo.KeyFlags = 4 Then
                Local $aIndices = _GUICtrlListView_GetSelectedIndices($iLV, True), $n
                For $n = 1 To $aIndices[0]
                    Switch Not _GUICtrlListView_GetItemChecked($iLV, $aIndices[$n])
                        Case False
                            _GUICtrlListView_SetItemParam($iLV, $aIndices[$n], 1000)
                            _GUICtrlListView_SetItemChecked($iLV, $aIndices[$n], False)
                        Case True
                            _GUICtrlListView_SetItemParam($iLV, $aIndices[$n], 1001)
                            _GUICtrlListView_SetItemChecked($iLV, $aIndices[$n], True)
                    EndSwitch
                Next
            EndIf
        Case $NM_DBLCLK
            Local $aInfo = GUIGetCursorInfo()
            Local $aTest = _GUICtrlListView_SubItemHitTest($iLV, $aInfo[0], $aInfo[1])
            If Not (Not $aTest[4] And $aTest[6]) Then
                $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
                Local $iChecked = _GUICtrlListView_GetItemParam($iLV, $tInfo.Index)
                If $iChecked = 1000 Then
                    _GUICtrlListView_SetItemParam($iLV, $tInfo.Index, 1001)
                    _GUICtrlListView_SetItemChecked($iLV, $tInfo.Index, True)
                Else
                    _GUICtrlListView_SetItemParam($iLV, $tInfo.Index, 1000)
                    _GUICtrlListView_SetItemChecked($iLV, $tInfo.Index, False)
                EndIf
            EndIf
        Case $NM_CLICK
            $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
            If $tInfo.KeyFlags = 4 Then
                $aIndices = _GUICtrlListView_GetSelectedIndices($iLV, True)
                ConsoleWrite(UBound($aIndices) - 1 & @CRLF)
                For $n = 1 To $aIndices[0]
                    Switch Not _GUICtrlListView_GetItemChecked($iLV, $aIndices[$n])
                        Case False
                            _GUICtrlListView_SetItemParam($iLV, $aIndices[$n], 1000)
                            _GUICtrlListView_SetItemChecked($iLV, $aIndices[$n], False)
                        Case True
                            _GUICtrlListView_SetItemParam($iLV, $aIndices[$n], 1001)
                            _GUICtrlListView_SetItemChecked($iLV, $aIndices[$n], True)
                    EndSwitch
                Next
            EndIf
        Case $NM_CUSTOMDRAW
          Local $tNMLVCUSTOMDRAW = DllStructCreate( $tagNMLVCUSTOMDRAW, $lParam )
          Local $dwDrawStage = DllStructGetData( $tNMLVCUSTOMDRAW, "dwDrawStage" )

          Switch $dwDrawStage                               ; Holds a value that specifies the drawing stage

            Case $CDDS_PREPAINT                             ; Before the paint cycle begins
              Return $CDRF_NOTIFYITEMDRAW                   ; Notify the parent window of any ITEM-related drawing operations

            Case $CDDS_ITEMPREPAINT                         ; Before painting an item
              Local $lItemlParam = $tNMLVCUSTOMDRAW.lItemlParam - 1000 ; Item param
              Local $uItemState  = $tNMLVCUSTOMDRAW.uItemState         ; Item state
              If $lItemlParam Then ; Checked rows
                If Not BitAnd( $uItemState, $CDIS_FOCUS ) Then
                  DllStructSetData( $tNMLVCUSTOMDRAW, "ClrText",   0xFFFFFF ) ; Forecolor white
                  DllStructSetData( $tNMLVCUSTOMDRAW, "clrTextBk", $iColor_TextBk ) ; Backcolor dark blue, BGR
                EndIf
              Else ; Other rows
                If Not BitAnd( $uItemState, $CDIS_FOCUS ) Then
                  DllStructSetData( $tNMLVCUSTOMDRAW, "ClrText",   0x000000 )
                  DllStructSetData( $tNMLVCUSTOMDRAW, "ClrTextBk", 0xFFFFFF )
                EndIf
              EndIf
              Return $CDRF_NEWFONT                          ; $CDRF_NEWFONT must be returned after changing font or colors

          EndSwitch

    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_NOTIFY

Br,
UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
LarsJ

I would separate checked and selected rows to make things easier:

 

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

$hGUI = GUICreate("ListView Test", 400, 550)
$iLV = GUICtrlCreateListView("", 0, 10, 400, 480, $LVS_SHOWSELALWAYS, BitOR($LVS_EX_FLATSB, $LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER))
_GUICtrlListView_AddColumn($iLV, "Date", 100, 1)
_GUICtrlListView_AddColumn($iLV, "Size (bytes)", 100, 1)
_GUICtrlListView_AddColumn($iLV, "File Name", 100, 1)
For $i = 0 to 150
    _GUICtrlListView_AddItem($iLV, "Row " & $i)
    _GUICtrlListView_AddSubItem($iLV, $i, $i * 2, 1)
    _GUICtrlListView_AddSubItem($iLV, $i, $i * 4, 2)
    _GUICtrlListView_SetItemParam($iLV, $i, 1000)
Next
_GUICtrlListView_SetItemChecked($iLV, 0)
_GUICtrlListView_SetItemParam($iLV, 0, 1001)
_GUICtrlListView_SetItemChecked($iLV, 1)
_GUICtrlListView_SetItemParam($iLV, 1, 1001)
_GUICtrlListView_SetItemChecked($iLV, 2)
_GUICtrlListView_SetItemParam($iLV, 2, 1001)
ControlFocus($hGUI, "", $iLV)

GUICtrlCreateLabel( "Space to invert checked state of selected items", 10, 500, 380, 20 )
GUICtrlSetFont( -1, 10, 700 )

GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

GUISetState()

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

Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
  #forceref $hWnd, $iMsg, $wParam
  Local $tNMHDR, $iCode
  $tNMHDR = DllStructCreate( $tagNMHDR, $lParam )
  $iCode = $tNMHDR.Code

  Switch $iCode
    Case $LVN_ITEMCHANGED
      Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam)
      If BitAND($tInfo.Changed, $LVIF_STATE) = $LVIF_STATE Then
        Switch $tInfo.NewState
          Case 8192 ;item checked
            _GUICtrlListView_SetItemParam($iLV, $tInfo.Item, 1001)
          Case 4096 ;item unchecked
            _GUICtrlListView_SetItemParam($iLV, $tInfo.Item, 1000)
        EndSwitch
      EndIf

    Case $LVN_KEYDOWN
      Local $tKey = DllStructCreate($tagNMLVKEYDOWN, $lParam)
      If $tKey.VKey = 0x20 Then ; $VK_SPACE = 0x20
        Local $aSelected = _GUICtrlListView_GetSelectedIndices($iLV, True)
        If $aSelected[0] > 1 Then ; $aSelected[0] = 1 is handled by default code
          For $i = 1 To $aSelected[0]
            If _GUICtrlListView_GetItemState($iLV, $aSelected[$i], $LVIS_FOCUSED ) Then ContinueLoop ; Handled by default code
            Local $fChecked = Not ( _GUICtrlListView_GetItemParam($iLV, $aSelected[$i]) = 1001 )
            _GUICtrlListView_SetItemParam($iLV, $aSelected[$i], $fChecked + 1000)
            _GUICtrlListView_SetItemChecked($iLV, $aSelected[$i], $fChecked)
            _GUICtrlListView_SetItemSelected($iLV, $aSelected[$i], False)
          Next
        EndIf
      EndIf

    Case $NM_DBLCLK
      Local $aInfo = GUIGetCursorInfo()
      Local $aTest = _GUICtrlListView_SubItemHitTest( $iLV, $aInfo[0], $aInfo[1] )
      If Not ( Not $aTest[4] And $aTest[6] ) Then
        $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
        Local $fChecked = Not ( _GUICtrlListView_GetItemParam($iLV, $tInfo.Index) = 1001 )
        _GUICtrlListView_SetItemParam($iLV, $tInfo.Index, $fChecked + 1000)
        _GUICtrlListView_SetItemChecked($iLV, $tInfo.Index, $fChecked)
      EndIf

    Case $NM_CUSTOMDRAW
      Local $tNMLVCUSTOMDRAW = DllStructCreate( $tagNMLVCUSTOMDRAW, $lParam )
      Local $dwDrawStage = DllStructGetData( $tNMLVCUSTOMDRAW, "dwDrawStage" )

      Switch $dwDrawStage                               ; Holds a value that specifies the drawing stage

        Case $CDDS_PREPAINT                             ; Before the paint cycle begins
          Return $CDRF_NOTIFYITEMDRAW                   ; Notify the parent window of any ITEM-related drawing operations

        Case $CDDS_ITEMPREPAINT                         ; Before painting an item
          Local $lItemlParam = $tNMLVCUSTOMDRAW.lItemlParam - 1000 ; Item param
          Local $uItemState  = $tNMLVCUSTOMDRAW.uItemState         ; Item state
          If $lItemlParam Then ; Checked rows
            If Not BitAnd( $uItemState, $CDIS_FOCUS ) Then
              ;DllStructSetData( $tNMLVCUSTOMDRAW, "ClrText",   0xFFFFFF ) ; Forecolor white
              ;DllStructSetData( $tNMLVCUSTOMDRAW, "clrTextBk", 0xCC6600 ) ; Backcolor dark blue, BGR
              DllStructSetData( $tNMLVCUSTOMDRAW, "clrTextBk", 0xFFFF00 ) ; Backcolor cyan, BGR
            EndIf
          Else ; Other rows
            If Not BitAnd( $uItemState, $CDIS_FOCUS ) Then
              ;DllStructSetData( $tNMLVCUSTOMDRAW, "ClrText",   0x000000 )
              ;DllStructSetData( $tNMLVCUSTOMDRAW, "ClrTextBk", 0xFFFFFF )
              DllStructSetData( $tNMLVCUSTOMDRAW, "ClrTextBk", 0xFFFFFF )
            EndIf
          EndIf
          Return $CDRF_NEWFONT                          ; $CDRF_NEWFONT must be returned after changing font or colors

      EndSwitch

  EndSwitch

  Return $GUI_RUNDEFMSG
EndFunc

Share this post


Link to post
Share on other sites
UEZ

Thanks LarsJ,

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
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
Sign in to follow this  

  • Similar Content

    • nacerbaaziz
      By nacerbaaziz
      Hello
      Dear Sirs, I have a question please
      About UPDown ctrl
      Where I want to adjust its format
      For example, I want to create a window to set the clock like the window in the system
      Can this be done?
      here's the example
      ______

      #include <WindowsConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <UpDownConstants.au3> goto() func Goto() local $wGoto = GUICreate("go to spissific position", 250, 180, @DesktopWidth / 2 - 192, @DesktopHeight / 2 - 235, -1) GUICtrlCreateLabel("please write a corect position to go to it", 50, 10, 220, 20) GUICtrlCreateLabel("hours", 0, 80, 100, 30) local $Inp1 = GUICtrlCreateInput("00", 0, 90, 100, 20, $ES_NUMBER + $WS_TABSTOP)     GUICtrlCreateUpdown($Inp1, $UDS_ARROWKEYS) GUICtrlSetLimit(-1, 23, 0) GUICtrlCreateLabel("minuts", 110, 80, 100, 30) local $Inp2 = GUICtrlCreateInput("00", 110, 90, 100, 20, $ES_NUMBER + $WS_TABSTOP)     GUICtrlCreateUpdown($Inp2, $UDS_ARROWKEYS) GUICtrlSetLimit(-1, 60, 0) GUICtrlCreateLabel("seconds", 220, 80, 100, 30) local $Inp3 = GUICtrlCreateInput("00", 220, 90, 100, 20, $ES_NUMBER + $WS_TABSTOP)     GUICtrlCreateUpdown($Inp3, $UDS_ARROWKEYS) GUICtrlSetLimit(-1, 60, 0) local $Ok = GUICtrlCreateButton("&ok", 0, 150, 50, 30, 0x01) local $cancel = GUICtrlCreateButton("&cancel", 200, 150, 50, 30) GUISetState(@sw_show, $WgoTo) while 1 switch GUIGetMSG() case $GUI_Event_Close, $cancel exit case $OK local $read1 = GUICtrlRead($inp1) if $read1 >= 1 then $Read1 = ($Read1*60)*60 local $read2 = GUICtrlRead($inp2) if $read2 >= 1 then $Read2 = $Read2*60 local $read3 = GUICtrlRead($inp3) GUIDelete($WgoTo) Return $read1+$read2+$read3 exit endSwitch Wend EndFunc
      ________
      What I need is to be the contents of the inputs as follows when i change the value of the UPDown CTRL
      00
      01
      02
      03
      ...
       
    • Broihon
      By Broihon
      Hey guys,

      I ran into a problem when I wanted to delete items of a listview using the delete key. My approach is to register my own WndProc for the listview and then filter the $WM_GETDLGCODE msg and then call the original WndProc.
      That works like a charm. The problem is that when the listview gets redrawn it somehow ends up in an infinite loop. The listview is suddenly emtpy and I can't interact with any controls of the GUI at all. Here's the code:
       
      #include <GUIConstantsEx.au3> #include <GUIListView.au3> #include <WinAPI.au3> $h_GUI = GUICreate("Test", 200, 200, 350, 350) $h_LV = GUICtrlCreateListView("Col 1|Col 2|Col 3", 0, 0, 200, 200) _GUICtrlListView_AddItem($h_LV, "") _GUICtrlListView_AddSubItem($h_LV, 0, "bla0", 0) _GUICtrlListView_AddSubItem($h_LV, 0, "bla0", 1) _GUICtrlListView_AddSubItem($h_LV, 0, "bla0", 2) _GUICtrlListView_AddItem($h_LV, "") _GUICtrlListView_AddSubItem($h_LV, 1, "bla1", 0) _GUICtrlListView_AddSubItem($h_LV, 1, "bla1", 1) _GUICtrlListView_AddSubItem($h_LV, 1, "bla1", 2) _GUICtrlListView_AddItem($h_LV, "") _GUICtrlListView_AddSubItem($h_LV, 2, "bla2", 0) _GUICtrlListView_AddSubItem($h_LV, 2, "bla2", 1) _GUICtrlListView_AddSubItem($h_LV, 2, "bla2", 2) _GUICtrlListView_AddItem($h_LV, "") _GUICtrlListView_AddSubItem($h_LV, 3, "bla3", 0) _GUICtrlListView_AddSubItem($h_LV, 3, "bla3", 1) _GUICtrlListView_AddSubItem($h_LV, 3, "bla3", 2) $h_LV_NewWndProc = DllCallbackRegister("WndProc_LV", "int", "hwnd;uint;wparam;lparam") $g_LV_OldWndProc = _WinAPI_SetWindowLong(GUICtrlGetHandle($h_LV), $GWL_WNDPROC, DllCallbackGetPtr($h_LV_NewWndProc)) GUISetState(@SW_SHOW) Func WndProc_LV($hWnd, $uMsg, $wParam, $lParam) Return _WinAPI_CallWindowProc($g_LV_OldWndProc, $hWnd, $uMsg, $wParam, $lParam) EndFunc ;==>WndProc_GUI Do Until GUIGetMsg() = $GUI_EVENT_CLOSE DllCallbackFree($h_LV_NewWndProc) As you can see I'm doing nothing in the WndProc of the listview. I'm simply calling the original WndProc. This still "freezes" when I mess with the width of the columns or in the original project when I add more items that they don't fit in the listview and I have to scroll. If I don't do that it's working fine.
    • c.haslam
      By c.haslam
      I have
      Local $idListview = GUICtrlCreateListView("",8,8,@DesktopWidth/2-16,@DesktopHeight-150,$LVS_SHOWSELALWAYS, _ $LVS_EX_INFOTIP) Local $hListView = GUICtrlGetHandle($idListview) _GUICtrlListView_InsertColumn($hListview, 0, "Filename", 400) _GUICtrlListView_InsertColumn($hListview, 1, "Ext", 50) _GUICtrlListView_InsertColumn($hListview, 2, "Size",70) _GUICtrlListView_InsertColumn($hListview, 3, 'Date time',100) _GUICtrlListView_InsertColumn($hListview, 4, "Path", 385) _GUICtrlListView_InsertColumn($hListview, 5, "sizeInt", 0) _GUICtrlListView_JustifyColumn($hListview, $kSize,1) ; right align then further on
      While True $sFnamExt = FileFindNextFile($iSrch) If @error Then ExitLoop EndIf $sAtts = FileGetAttrib($sPath&'\'&$sFnamExt) If StringInStr($sAtts,'D') Then If $sFnamExt<>'$RECYCLE.BIN' Then $sDirs &= '?'&$sPath&'\'&$sFnamExt EndIf Else $p = StringInStr($sFnamExt,'.',0,-1) ; last If $p=0 Then $sFnam = $sFnamExt $sExt = '' Else $sFnam = StringLeft($sFnamExt,$p-1) $sExt = StringTrimLeft($sFnamExt,$p) EndIf _GUICtrlListView_AddItem($hListview,$sFnam,-1,_GUICtrlListView_GetItemCount($hListview)+1000) _GUICtrlListView_AddSubItem($hListview,$nItem,$sExt,$kExt) $nSize = FileGetSize($sPath&'\'&$sFnamExt) $sSize = AddThousandsSeparator($nsize) _GUICtrlListView_AddSubItem($hListview,$nItem,$sSize,$kSize) _GUICtrlListView_AddSubItem($hListview,$nItem,$nsize,$kSizeInt) $nTotBytes += $nSize $a1 = FileGetTime($sPath&'\'&$sFnamExt,$FT_MODIFIED,$FT_ARRAY) $t = $a1[0]&'-'&$a1[1]&'-'&$a1[2]&' '&$a1[3]&':'&$a1[4] _GUICtrlListView_AddSubItem($hListview,$nItem,$t,$kDateTime) _GUICtrlListView_AddSubItem($hListview,$nItem,$sPath,$kPath) If $gSQL Then $s = "Insert into tbl values ("&_SQLite_Escape($sFnam)&","&_SQLite_Escape($sExt)&",'"& _ $sSize&"','"& _ $t&"',"&_SQLite_Escape($sPath)&","&$nSize&")" _SQLite_Exec(-1,$s) If @error Then MsgBox(0,@ScriptLineNumber,_SQLite_ErrMsg()) EndIf EndIf EndIf WEnd FileClose($iSrch) You will see that I heeded the advice in Help > _GUICtrlListView_AddItem: "As AutoIt uses the $iParam parameter to store the controlID of native-created ListView items, this value should be set sufficiently high for UDF-created items to avoid possible conflict with any existing controls - a starting value of 1000 is recommended."
      (It's unfortunate that the Example does not heed this advice. OK, it doesn't need to because there are no other controls, but still --- it would help neophytes if it did. Also to me _GUICtrlListView_AddItem is not native because it is a UDF. Confused?)
      My script then does a sort using SQLite, and updates the ListView:
      Local $hQuery Local $colNames = ['fnam','ext','nsize','dateTime','path','SizeInt'] Local $s = "Select * FROM tbl ORDER BY "&$colNames[$ncol]&';' _SQLite_Query(-1,$s, $hQuery) If @error Then MsgBox(0,@ScriptLineNumber,_SQLite_ErrMsg()) EndIf Local $aRow[$kSizeInt+1] Local $iItem=-1 While _SQLite_FetchData($hQuery, $aRow, False, False) = $SQLITE_OK ; Read Out the next Row If @error Then MsgBox(0,@ScriptLineNumber,_SQLite_ErrMsg()) EndIf $iItem += 1 For $i = $kFnam To $kSizeInt _GUICtrlListView_SetItem($hListview,$aRow[$i],$iItem,$i,Default) Next WEnd This works, but I had earlier coded
      _GUICtrlListView_SetItem($hListview,$aRow[$i],$iItem,$i,Default,$iItem+1000) because the same advice is in the Help for this function.
      So my care in specifying $param back-fired! What am I not understanding?
      The only difference in what works is that the $param parameter is defaulted.
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good evening everyone
      I am building a management for the company I work with, and I just imported a real amount of rows ( about 29000 ), in my SQLite DB.
      The thing I am not understanding, is the time that the script takes to build this amount of rows in the ListView.
      I didn't measure it, but I think it took 2 minutes or so to create each ListView item...
      It is normal that it takes so much time?
      What can I do to improve the creation of the items?

      Here's the code I am using to query and to create ListView items...
      ; Articles ListView: Global $lvwArticles = GUICtrlCreateListView("ID|Fornitore|Codice|Descrizione|EU|Prezzo|Sconto Applicato|Note", 14, 87, 1507, 660, BitOR($GUI_SS_DEFAULT_LISTVIEW,$LVS_SORTASCENDING,$LVS_SORTDESCENDING), BitOR($WS_EX_CLIENTEDGE,$LVS_EX_GRIDLINES,$LVS_EX_FULLROWSELECT)) ; Query $strQuery = "SELECT * FROM ARTICOLI;" ; Query Execution _SQLite_GetTable2d($objDatabase, $strQuery, $arrResult, $intRows, $intColumns) If @error Then ; Error Handling Else ; Cleaning the ListView _GUICtrlListView_DeleteAllItems($lvwArticles) If @error Then ; Error Handling Else ; No records in the Table If UBound($arrResult) < 2 Then ; Error Handling Else _GUICtrlListView_BeginUpdate($lvwArticles) For $intCounter = 1 To UBound($arrResult) - 1 $strListViewItem = $arrResult[$intCounter][0] & "|" & _ $arrResult[$intCounter][1] & "|" & _ $arrResult[$intCounter][2] & "|" & _ $arrResult[$intCounter][3] & "|" & _ $arrResult[$intCounter][4] & "|" & _ $arrResult[$intCounter][5] & "|" & _ $arrResult[$intCounter][6] & "|" & _ $arrResult[$intCounter][7] $objListViewItem = GUICtrlCreateListViewItem($strListViewItem, $lvwArticles) Next _GUICtrlListView_EndUpdate($lvwArticles) EndIf EndIf EndIf Thanks in advance


      Best Regards.
    • Skysnake
      By Skysnake
      I am tracking this topic by @LarsJ.  It is very advanced and overkill for what I am currently trying to do.
       
      Problem is this.
      Listview contains columns, one of which is right aligned and gets populated by float values, such as 123.99.  Some do not have decimals ie 124.00 and on sort gets truncated to 124.  Its obviously still the same value, but the display has reset.
      ; line below is for list VIEW ;..................................0.........1......2............ $cListView = GUICtrlCreateListView("CUSTOMER|AMOUNT|DESCRIPTION", 8, 152, 764, 279) GUICtrlSetBkColor($cListView, $GUI_BKCOLOR_LV_ALTERNATE) ; alternate between the listview background color and the listview item background color GUICtrlSetBkColor($cListView, $LVStdClr) ; Set the background color for the listview _GUICtrlListView_SetColumnWidth($cListView, 0, 120) ; -- the client name _GUICtrlListView_SetColumnWidth($cListView, 1, 90) ;-- the amount _GUICtrlListView_JustifyColumn($cListView, 1, 1) ; 1 - Text is right aligned _GUICtrlListView_SetColumnWidth($cListView, 2, 200) ; the description What I am looking for is something native and simple like a 
          _GUICtrlListView_SetColumnFormat($cListView, 1, "%.2f") ;  1 - column is stringformatted to "%.2f"
      So that after each sort it will appear as it was in the original rendering.
      Is there something like this? I have not been able to find a simple solution.

      Thanks.
      Skysnake
×