Jump to content
Sign in to follow this  
AndyS01

Set checkboxes on just certain items in a ListView control

Recommended Posts

AndyS01
I'm trying to put a check box next to just some of the items in a ListView control.  I know how to create listview controls with check boxes for ALL items, but not for just SOME of them.  I figured that the only way to do this is to put images of check boxes in the first column, then change the image when I wanted to check or uncheck the item or to change to have no check box at all.
 
An example might be:
Choose one of the following:
[] Apples
[] Oranges
In my test code below, I tried using icons of checked and unchecked images, but I couldn't get that to work.
 
;Add extra ICO files to the resources which can be used with TraySetIcon(@ScriptFullPath, 3) etc
; list of filename of the Ico files to be added, First one will have number 3, then 4 ..etc
#AutoIt3Wrapper_Res_Icon_Add=C:\checked.ico
#AutoIt3Wrapper_Res_Icon_Add=C:\unchecked.ico

Opt("GUICloseOnESC", 1) ; ESC closes GUI
Opt("GUIOnEventMode", 1) ; Change to OnEvent mode
;Opt('MustDeclareVars', 1)
OnAutoItExitRegister("ExitStageLeft_normal")
;Opt("WinTitleMatchMode", -1) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase

#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>

GUICreate("ListView Set Item Image", 220, 400)

$hListView = GUICtrlCreateListView("", 2, 2, 204, 368)

$btn1 = GUICtrlCreateButton("Apples", 5, 400 - 30, 50, 25)
GUICtrlSetOnEvent($btn1, "handle_btn1")

$btn2 = GUICtrlCreateButton("Oranges", 5 + 50, 400 - 30, 70, 25)
GUICtrlSetOnEvent($btn2, "handle_btn2")

GUISetOnEvent($GUI_EVENT_CLOSE, 'ExitStageLeft_normal') ; CLOSE events

GUISetState()

; Load images
$hImage = _GUIImageList_Create(16, 16, 5, 3)

$b1 = _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0xFF0000, 16, 16)); red
$b2 = _GUIImageList_AddIcon($hImage, "C:\checked.ico.ico")
$b3 = _GUIImageList_AddIcon($hImage, "C:\Uunchecked.ico.ico")
$b4 = _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0x00FF00, 16, 16)); green

; Attach the list to the listview control
_GUICtrlListView_SetImageList($hListView, $hImage, 1)

; Add a column
_GUICtrlListView_AddColumn($hListView, "Column 1", 200)

_GUICtrlListView_AddItem($hListView, "", 5)
_GUICtrlListView_AddItem($hListView, "Choose one of the following:", 5)

$itemnum_choice1 = _GUICtrlListView_AddItem($hListView, "Apples", 5)
$itemnum_choice2 = _GUICtrlListView_AddItem($hListView, "Oranges", 5)

ConsoleWrite("+++: $b1 = " & $b1 & ", $b2 = " & $b2 & ", $b3 = " & $b3 & ", $b4 = " & $b4 & @CRLF)

; Loop until user exits
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()

Func handle_btn1()
    cycle($itemnum_choice1) ; cycle 'apples' between checked, unchecked, and no checkbox
EndFunc   ;==>handle_btn1

Func handle_btn2()
    cycle($itemnum_choice2) ; cycle 'oranges' between checked, unchecked, and no checkbox
EndFunc   ;==>handle_btn2

 ; cycle 'an item between checked, unchecked, and no checkbox
 Func cycle($itemnum)
    $p = _GUICtrlListView_GetItemParam($hListView, $itemnum)
    $p += 1
    _GUICtrlListView_SetItemParam($hListView, $itemnum, $p)

    Switch Mod($p, 3)
        Case 0
            $i = $b2 ; Checked
        Case 1
            $i = $b3 ; Unchecked
        Case 2
            $i = 5 ; no checkbox
    EndSwitch

    _GUICtrlListView_SetItemImage($hListView, $itemnum, $i)
    ConsoleWrite("+++: Item: " & $itemnum & " - " & $i & @CRLF)
EndFunc   ;==>toggle

Func ExitStageLeft_normal()
    Exit
EndFunc   ;==>ExitStageLeft_normal

Share this post


Link to post
Share on other sites
FireFox

Hi,

AFAIK, you can't set a checkbox for some items.

My suggestion is to handle the click and block it for the items you don't want to have a checkbox (cf: WM_NOTIFY).

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
AndyS01

I changed the test code to not use check boxes, but instead, puts a a 'checked' or 'unchecked' image for a each item in the ListView that I want to have a check box.  It works like I would like it to work (see test code below), but this test code displays a solid green for checked, a solid red box for unchecked, and no box for 'not a check box'.

However, I want to use my icons instead of the solid boxes.  I want my icons to be inserted into the executable file so I don't have to ship the .ico files separately from my executable file.

Here's my test code:

#AutoIt3Wrapper_Res_Icon_Add=C:\checked.ico
#AutoIt3Wrapper_Res_Icon_Add=C:\unchecked.ico

Opt("WinTitleMatchMode", 1)
Opt("GUIOnEventMode", 1)
Opt("GUICloseOnESC", 1)
OnAutoItExitRegister("ExitStageLeft")

#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>

GUICreate("ListView Set Item Image", 220, 400)
$hListView = GUICtrlCreateListView("", 2, 2, 204, 368)
GUICtrlCreateButton("CHECK", 5, 370, 65, 25)
GUICtrlSetOnEvent(-1, "handle_btn1")
GUICtrlCreateButton("UNCHECK", 70, 370, 65, 25)
GUICtrlSetOnEvent(-1, "handle_btn2")
GUICtrlCreateButton("NOCHECK", 135, 370, 65, 25)
GUICtrlSetOnEvent(-1, "handle_btn3")
GUISetState()

; Load images
$hImage = _GUIImageList_Create(16, 16, 5, 3)
$a1 = _GUIImageList_Add($hImage, "C:\checked.ico")
$a2 = _GUIImageList_Add($hImage, "C:\unchecked.ico")
$a3 = _GUIImageList_AddIcon($hImage, @SystemDir & "shell32.dll", 110)
$a4 = _GUIImageList_AddIcon($hImage, @SystemDir & "shell32.dll", 131)
$a5 = _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0xFF0000, 16, 16)); red
$a6 = _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0x00FF00, 16, 16)); green
$a7 = _GUICtrlListView_SetImageList($hListView, $hImage, 1)

; Add columns
_GUICtrlListView_AddColumn($hListView, "Column 1", 150)

; Add items
$iconnum = -7
For $x = 0 To 12
    $iconnum += 1
    $str = "Item# " & $x & " - Icon# " & $iconnum
    $ndx = _GUICtrlListView_AddItem($hListView, $str, $iconnum)
    _GUICtrlListView_SetItemImage($hListView, $ndx, $iconnum)
Next

ConsoleWrite("+++: " & StringFormat("$a1 = %d, $a2 = %d, $a3 = %d, $a4 = %d, $a5 = %d, %a7 = %d", $a1, $a2, $a3, $a4, $a5, $a6, $a7) & @CRLF)
GUISetOnEvent($GUI_EVENT_CLOSE, 'ExitStageLeft')

; Loop until user exits
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Func ExitStageLeft()
    Exit
EndFunc   ;==>ExitStageLeft

Func handle_btn1()
    testfunc(1)
EndFunc   ;==>handle_btn1

Func handle_btn2()
    testfunc(0)
EndFunc   ;==>handle_btn2

Func handle_btn3()
    testfunc(6)
EndFunc   ;==>handle_btn3

Func testfunc($which)
    $iIndex = 10
    $iImage = $which
    $hWnd = $hListView

    $ret = _GUICtrlListView_SetItemImage($hWnd, $iIndex, $iImage)

    ConsoleWrite("+++: _GUICtrlListView_SetItemImage(" & Hex($hWnd) & ", $iIndex = " & $iIndex & ", $iImage = " & $iImage & ") returns: " & $ret & @CRLF)
EndFunc   ;==>testfunc

Share this post


Link to post
Share on other sites
Artisan

You could include custom images, but it would be easier to grab the icon out of the appropriate Windows DLL file.  Then you don't have to include anything.  (I have no idea which one that is, and I've checked a few dozen so far...)

I started with the assumption that control faces would be icons within a dll.  On reflection, that seems fairly stupid.  My bad.  And I'm pretty sure it would be comctl32.dll, but they're not in there.

Anyway, you can include icon files at compile time (it's an option if you're using SciTE), or you can draw one using GDI(+) and use that for your image (I think).

Edited by Artisan

Share this post


Link to post
Share on other sites
Edano

you have to create an imagelist with all the icons you need.

_GUIImageList_Create()

.

then you set the imagelist to the listview.

.

_GUICtrlListView_SetImageList()

.

in the image list, they are indexed, and you simply use the index with listviewsetitem or how the name is.

you can pull the imagelist icons out of the own exe when you have included the icons to the resource with

.

#AutoIt3Wrapper_Res_Icon_Add=

.

before compilation.

cheers E.

Edit: click on the functions in the tags to get examples

Edit: i just saw that you already managed the imagelist part. then you only need the autoitwrapper working. you find the icons then like createicon("myexe",-5) as example. always "-" for autoit.

Edited by Edano

[color=rgb(255,0,0);][font="'comic sans ms', cursive;"]FukuLeaks[/color][/font]

Share this post


Link to post
Share on other sites
AndyS01

I already had the 2 autoitwrapper lines at the top of the script.  I modified my test script a bit, and added the capability of entering an icon#.  As before, no numbers I plugged in worked.  Do you think you could run my script (with your icons), and see if it works for you?

I'm still looking for a dll with 'check' and 'uncheck' icons.

My check and uncheck icons show up in the list of icons embedded in the .exe file (using IcoFX).  If the icons are embedded, why can't I get to them via image list?

#AutoIt3Wrapper_Res_Icon_Add=C:\checked.ico
#AutoIt3Wrapper_Res_Icon_Add=C:\unchecked.ico

Opt('MustDeclareVars', 1)
Opt("WinTitleMatchMode", 1)
Opt("GUIOnEventMode", 1)
Opt("GUICloseOnESC", 1)
OnAutoItExitRegister("ExitStageLeft")

#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>

Global $hMainWin, $iID_InputCtrl, $hListView

_Main()
Exit

Func _Main()
    Local $hImage, $a1, $a2, $a3, $a4, $a5, $a6, $a7, $iconnum, $str, $ndx

    $hMainWin = GUICreate("ListView Set Item Image", 220, 400)
    $hListView = GUICtrlCreateListView("", 2, 2, 204, 280)
    GUICtrlCreateButton("CHECK", 5, 290, 65, 25)
    GUICtrlSetOnEvent(-1, "handle_Check_btn")
    GUICtrlCreateButton("UNCHECK", 70, 290, 65, 25)
    GUICtrlSetOnEvent(-1, "handle_UnCheck_btn")
    GUICtrlCreateButton("HIDECHECK", 135, 290, 70, 25)
    GUICtrlSetOnEvent(-1, "handle_HideCheckBox_btn")
    $iID_InputCtrl = GUICtrlCreateInput("", 10, 320, 100, 25)
    GUICtrlCreateButton("Icon#", 10, 345, 65, 25)
    GUICtrlSetOnEvent(-1, "handle_btn4")
    GUISetState()

    ; Load images
    $hImage = _GUIImageList_Create(16, 16, 5, 3)

    $a1 = _GUIImageList_Add($hImage, "C:\checked.ico") ; returns -1
    $a2 = _GUIImageList_Add($hImage, "C:\unchecked.ico") ; returns -1
    $a3 = _GUIImageList_AddIcon($hImage, @SystemDir & "shell32.dll", 110) ; returns 0
    $a4 = _GUIImageList_AddIcon($hImage, @SystemDir & "shell32.dll", 131) ; returns 0
    $a5 = _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0xFF0000, 16, 16)); red ; returns 0
    $a6 = _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0x00FF00, 16, 16)); green ; returns 1

    ; Attach imagelist to the ListView control
    $a7 = _GUICtrlListView_SetImageList($hListView, $hImage, 1)

    ; Add columns
    _GUICtrlListView_AddColumn($hListView, "Column 1", 150)

    ; Add items
    $iconnum = -7
    For $x = 0 To 12
        $iconnum += 1
        $str = "Item# " & $x & " - Icon# " & $iconnum
        $ndx = _GUICtrlListView_AddItem($hListView, $str, $iconnum)
        _GUICtrlListView_SetItemImage($hListView, $ndx, $iconnum)
    Next

    ; Change the text for line 10
    _GUICtrlListView_SetItem($hListView, "LINE 10", 10)

    ConsoleWrite("+++: " & StringFormat("$a1 = %d, $a2 = %d, $a3 = %d, $a4 = %d, $a5 = %d, $a6 = %d, $a7 = %d", $a1, $a2, $a3, $a4, $a5, $a6, $a7) & @CRLF)
    ConsoleWrite("+++: $a7 = " & $a7 & @CRLF)

    GUISetOnEvent($GUI_EVENT_CLOSE, 'ExitStageLeft')

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
EndFunc   ;==>_Main

Func ExitStageLeft()
    Exit
EndFunc   ;==>ExitStageLeft

Func handle_Check_btn()
    testfunc(0)
EndFunc   ;==>handle_Check_btn

Func handle_UnCheck_btn()
    testfunc(1)
EndFunc   ;==>handle_UnCheck_btn

Func handle_HideCheckBox_btn()
    testfunc(2)
EndFunc   ;==>handle_HideCheckBox_btn

Func handle_btn4()
    Local $iIndex = GUICtrlRead($iID_InputCtrl)
    testfunc($iIndex)
EndFunc   ;==>handle_btn4

Func testfunc($iImageNum)
    ConsoleWrite("+++: $iImageNum = " & $iImageNum & @CRLF)
    Local $iIndex, $hWnd, $ret

    $iIndex = 10
    $hWnd = $hListView

    $ret = _GUICtrlListView_SetItemImage($hWnd, $iIndex, $iImageNum)

    ConsoleWrite("+++: _GUICtrlListView_SetItemImage(" & Hex($hWnd) & ", $iIndex = " & $iIndex & ", $iImageNum = " & $iImageNum & ") returns: " & $ret & @CRLF)
EndFunc   ;==>testfunc

Share this post


Link to post
Share on other sites
NewPlaza

How about this?

#AutoIt3Wrapper_Res_Icon_Add=C:\checked.ico
#AutoIt3Wrapper_Res_Icon_Add=C:\unchecked.ico

Opt('MustDeclareVars', 1)
Opt("WinTitleMatchMode", 1)
Opt("GUIOnEventMode", 1)
Opt("GUICloseOnESC", 1)
OnAutoItExitRegister("ExitStageLeft")

#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>

Global $hMainWin, $iID_InputCtrl, $hListView

_Main()
Exit

Func _Main()
    Local $hImage, $a1, $a2, $a3, $a4, $a5, $a6, $a7, $iconnum, $str, $ndx

    $hMainWin = GUICreate("ListView Set Item Image", 220, 400)
    $hListView = GUICtrlCreateListView("", 2, 2, 204, 280)
    GUICtrlCreateButton("CHECK", 5, 290, 65, 25)
    GUICtrlSetOnEvent(-1, "handle_Check_btn")
    GUICtrlCreateButton("UNCHECK", 70, 290, 65, 25)
    GUICtrlSetOnEvent(-1, "handle_UnCheck_btn")
    GUICtrlCreateButton("HIDECHECK", 135, 290, 70, 25)
    GUICtrlSetOnEvent(-1, "handle_HideCheckBox_btn")
    $iID_InputCtrl = GUICtrlCreateInput("", 10, 320, 100, 25)
    GUICtrlCreateButton("Icon#", 10, 345, 65, 25)
    GUICtrlSetOnEvent(-1, "handle_btn4")
    GUISetState()

    ; Load images
    $hImage = _GUIImageList_Create(16, 16, 5, 3)

    $a1 = _GUIImageList_AddIcon($hImage, @ScriptFullPath, 4) ; returns -1
    $a2 = _GUIImageList_AddIcon($hImage, @ScriptFullPath, 5) ; returns -1
    $a3 = _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 110) ; returns 0; The backslash was forgotten
    $a4 = _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 131) ; returns 0; The backslash was forgotten
    $a5 = _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0xFF0000, 16, 16)); red ; returns 0
    $a6 = _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0x00FF00, 16, 16)); green ; returns 1

    ; Attach imagelist to the ListView control
    $a7 = _GUICtrlListView_SetImageList($hListView, $hImage, 1)

    ; Add columns
    _GUICtrlListView_AddColumn($hListView, "Column 1", 150)

    ; Add items
    $iconnum = -7
    For $x = 0 To 12
        $iconnum += 1
        $str = "Item# " & $x & " - Icon# " & $iconnum
        $ndx = _GUICtrlListView_AddItem($hListView, $str, $iconnum)
        _GUICtrlListView_SetItemImage($hListView, $ndx, $iconnum)
    Next

    ; Change the text for line 10
    _GUICtrlListView_SetItem($hListView, "LINE 10", 10)

    ConsoleWrite("+++: " & StringFormat("$a1 = %d, $a2 = %d, $a3 = %d, $a4 = %d, $a5 = %d, $a6 = %d, $a7 = %d", $a1, $a2, $a3, $a4, $a5, $a6, $a7) & @CRLF)
    ConsoleWrite("+++: $a7 = " & $a7 & @CRLF)

    GUISetOnEvent($GUI_EVENT_CLOSE, 'ExitStageLeft')

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
EndFunc   ;==>_Main

Func ExitStageLeft()
    Exit
EndFunc   ;==>ExitStageLeft

Func handle_Check_btn()
    testfunc(0)
EndFunc   ;==>handle_Check_btn

Func handle_UnCheck_btn()
    testfunc(1)
EndFunc   ;==>handle_UnCheck_btn

Func handle_HideCheckBox_btn()
    testfunc(2)
EndFunc   ;==>handle_HideCheckBox_btn

Func handle_btn4()
    Local $iIndex = GUICtrlRead($iID_InputCtrl)
    testfunc($iIndex)
EndFunc   ;==>handle_btn4

Func testfunc($iImageNum)
    ConsoleWrite("+++: $iImageNum = " & $iImageNum & @CRLF)
    Local $iIndex, $hWnd, $ret

    $iIndex = 10
    $hWnd = $hListView

    $ret = _GUICtrlListView_SetItemImage($hWnd, $iIndex, $iImageNum)

    ConsoleWrite("+++: _GUICtrlListView_SetItemImage(" & Hex($hWnd) & ", $iIndex = " & $iIndex & ", $iImageNum = " & $iImageNum & ") returns: " & $ret & @CRLF)
EndFunc   ;==>testfunc

NOTE: You MUST compile with options! This is a must.  The icons will embed into the autoitEXE but you will not be able to use them(as far as I can tell).

Simply right-click the au3 file and select compile with Options. Then click Compile Script.

Share this post


Link to post
Share on other sites
dragan

 

 I figured that the only way to do this is to put images of check boxes in the first column, then change the image when I wanted to check or uncheck the item or to change to have no check box at all.

 

Erm... not the only way:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <WinAPI.au3>

$Form1 = GUICreate("Form1", 180, 600)
$ListView1 = GUICtrlCreateListView('Item', 0, 0, 180, 600, BitOR($LVS_SHOWSELALWAYS, $LVS_SINGLESEL), BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES, $LVS_EX_DOUBLEBUFFER))
_GUICtrlListView_SetColumnWidth(GUICtrlGetHandle($ListView1), 0, 150)
For $i = 0 to 49
    Local $curIndex = _GUICtrlListView_GetItemCount(GUICtrlGetHandle($ListView1))
    _GUICtrlListView_InsertItem(GUICtrlGetHandle($ListView1), 'Item ------------ #' & $i+1)

    ;disable checkbox for:
    ;    - item @ index 4 (item #5)
    ;    - item @ index 24 (item #25)
    ;    - item @ index 34 (item #35)
    ;    - all items between index 9(#10) and 19(#20) = {10, 11, 12, 13... 19, 20}
    ;    - item @ index 48 (item #49)
    Switch $i
        Case 4, 24, 34, 9 to 19, 48
            _RemoveCheckbox(GUICtrlGetHandle($ListView1), $i)
    EndSwitch
Next
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") ;required for preventing checkboxes from re-apearing

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

Func _RemoveCheckbox($LVM, $nIndex)
    _GUICtrlListView_SetItemState($LVM, $nIndex, 0, $LVIS_STATEIMAGEMASK)
    _WinAPI_RedrawWindow($LVM)
EndFunc

Func WM_NOTIFY($hWndGUI, $MsgID, $WParam, $LParam)
    #forceref $hWndGUI, $MsgID, $wParam
    Local $tNMHDR, $hwndFrom, $code, $tInfo
    $tNMHDR = DllStructCreate($tagNMHDR, $LParam)
    $hwndFrom = DllStructGetData($tNMHDR, "hWndFrom")
    $code = DllStructGetData($tNMHDR, "Code")
    Local $hWndListView = $ListView1
    If Not IsHWnd($ListView1) Then $hWndListView = GUICtrlGetHandle($ListView1)
    Switch $hwndFrom
        Case $hWndListView
            Switch $code
                Case $NM_CLICK, $NM_DBLCLK, $NM_RCLICK, $NM_RDBLCLK
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $LParam)
                    ;preventing checkboxes from re-apearing (same conditions as above)
                    Switch DllStructGetData($tInfo, "Index")
                        Case 4, 24, 34, 9 to 19, 48
                            Return True;intercept normal return message which would cause checkbox to re-apear
                    EndSwitch
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc
Edited by dragan

Share this post


Link to post
Share on other sites
AndyS01

That's exactly what I was looking for.  I added those techniques to my test script and it worked beautifully.  Thank you.

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

    • OneSolution
      By OneSolution
      Hi guys! I have these checkbox that I'm trying to click on. They have the same inner-text string but a different ID. Sometime there can be as many as 4 checkbox
      with the same string but the ID is always different. I tried a few methods down below but I'm unable to make any real results. Any suggestions or solutions I would
      appreciate it very much.
      <ul><li class="cx-list-item-wrapper" data-day="Aug 2 2018 07:27:37 GMT-0700 (Pacific Daylight Time)"><div class=""><div class="cx-list-item-container"><div class="cx-list-item cx-item-icon-2 pointer-cursor"><div class="cx-item-contents cx-item-time col-md-2"><!-- react-text: 675 -->Morning<!-- /react-text --><!-- react-text: 676 -->&nbsp;<!-- /react-text --></div><div class="cx-item-contents col-md-1"><!-- react-text: 678 -->OTHER<!-- /react-text --><!-- react-text: 679 -- >&nbsp;<!-- /react-text --></div><div class="cx-item-contents col-md-2"><!-- react-text: 681 -->8:30 AM<!-- /react-text --><!-- react-text: 682 -->&nbsp;<!-- /react-text --></div><div class="cx-item-contents col-md-2"><!-- react-text: 684 -->10:30 AM<!-- /react-text --><!-- react-text: 685 -->&nbsp;<!-- /react-text -- ></div><div class="cx-item-contents col-md-1"><!-- react-text: 687 -->SRV<!-- /react-text --><!-- react-text: 688 -->&nbsp;<!-- /react-text --></div></div></div><div class="pull-right cx-listitem-chk"><div><input id="cx_checkbox1" class="cx-fa-chk cx-selfschedule-chk" value="on" type="checkbox"><label for="cx_checkbox1"></label></div></div></div></li><li class="cx-list-item-wrapper" data-day="Aug 2 2018 07:27:37 GMT-0700 (Pacific Daylight Time)"><div class=""><div class="cx-list-item-container"><div class="cx-list-item cx-item-icon-2 pointer-cursor"><div class="cx-item-contents cx-item-time col-md-1"><!-- react-text: 698 -- >Morning<!-- /react-text --><!-- react-text: 699 -->&nbsp;<!-- /react-text --></div><div class="cx-item-contents col-md-1"><!-- react-text: 701 -->OTHER<!-- /react- text --><!-- react-text: 702 -->&nbsp;<!-- /react-text --></div><div class="cx-item-contents col-md-2"><!-- react-text: 704 -->8:30 AM<!-- /react-text --><!-- react-text: 705 -->&nbsp;<!-- /react-text --></div><div class="cx-item-contents col-md-2"><!-- react-text: 707 -->2:30 PM<!-- /react-text --><!-- react-text: 708 -- >&nbsp;<!-- /react-text --></div><div class="cx-item-contents col-md-1"><!-- react-text: 710 -->SRV<!-- /react-text --><!-- react-text: 711 -->&nbsp;<!-- /react-text --></div></div></div><div class="pull-right cx-listitem-chk"><div><input id="cx_checkbox2" class="cx-fa-chk cx-selfschedule-chk" value="on" type="checkbox"><label for="cx_checkbox2"></label></div></div></div></li></ul> I tried the _IETagNameGetCollection() but it only check the box but doesn't fire the event! And I'm unable to submit that without a click action.
      Func _Box1() $oInputs = _IETagNameGetCollection($oIE, "input") For $oInput In $oInputs If $oInput.id == "cx_checkbox1" Then $oInput.checked = true Next Sleep(10) ToolTip('box1') EndFunc ;==>_Box1 I also tried click by text.The boxes do get check by a click but the problem with that is it will select every box that has the same string. I'm allowed only to check 1 box selection at a time per day for the submit button to work.  Any preference to select only the second box and bypass the other?
      Func _Morning() For $a In _IETagNameGetCollection($oIE, "div") If StringInStr(_IEPropertyGet($a, "innerText"), "Morning") Then _IEAction($a, "click") EndIf Next Sleep(10) ToolTip('Morning selected') EndFunc ;==>Morning The last method I tried was _IEGetObjById(). It doesn't click or respond to the checkbox.
      Func _Click1() $oChk = _IEGetObjById($oIE, "cx_checkbox1") _IEAction($oChk, 'click') Sleep(20) ToolTip('box1') EndFunc ;==>_Click1  
    • 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
×