Jump to content

Stuck on reading ListViewItems w/checkboxes


drwoobie
 Share

Recommended Posts

Hi all,

I am stuck trying to figure out how to get the contents of ListViewItems with checkbox controls (to pass on to other functions).

I've been looking at the forum, but I think I've confused myself even more.

Here's my testing code:

CODE

#NoTrayIcon

#include <GuiConstants.au3>

#include <ListViewConstants.au3>

; GUI

GuiCreate("list item select issue", 420, 400)

$currentView = GuiCtrlCreateListView("Col A | Col B", 5, 26, 203, 275, -1, BitOR( $LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT))

For $i = 1 To 3

GuiCtrlCreateListViewItem( "Item " & $i & "|" & "SubItem " & $i, $currentView)

Next

; BUTTON

$showMe = GuiCtrlCreateButton("Show Me", 5, 306, 65, 20)

; GUI MESSAGE LOOP

GuiSetState()

While 1

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

ExitLoop

Case $msg = $showMe

MsgBox ( 4096, "Results", GUICtrlRead($currentView, 1))

EndSelect

WEnd

GUIDelete()

Exit

In all my testing of what I could find in the way of answers on the forum, the behavior of this code is the best result I have been able to manage.

Selecting a "line" item and clicking the button causes the msgbox to display (I assume) the line item's place value (1st line shows value "4") etc.

If I unselect a line and check a checkbox, the msgbox displays "0".

My goal is to be able to select a checkbox and sending the corresponding information to the next function.

What functions do I need to be looking at to get the functionality I want?

Edited by drwoobie

Thanks,drwoobieMy Projects:Network Drive Profile Tool

Link to comment
Share on other sites

so to help you out...

#include<GUIConstantsEx.au3>
#include<ListViewConstants.au3>
#include<StructureConstants.au3>
#include<WindowsConstants.au3>
#include<GuiListView.au3>


Global $gui,$sel, $hListView
; GUI
$gui=GuiCreate("list item select issue", 420, 400)

$hListView = GuiCtrlCreateListView("Col A | Col B", 5, 26, 203, 275, -1, BitOR( $LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT))
For $i = 1 To 3
GuiCtrlCreateListViewItem( "Item " & $i & "|" & "SubItem " & $i, $hListView)
Next

; BUTTON
$label = GUICtrlCreateLabel("RESULTS ARE HERE", 5, 306, 165, 20)


GuiSetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

While 1
sleep(50)
WEnd


Exit
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo

    $hWndListView = $hListView
    If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_CLICK; Sent by a list-view control when the user clicks an item with the left mouse button
                   $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
                    $sel = DllStructGetData($tInfo, "Index")
                
                
                  GUICtrlSetData($label, _GUICtrlListView_GetItemTextString($hListView,$sel))
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc  ;==>WM_NOTIFY
Link to comment
Share on other sites

your welcome ;) Anytime and Welcome to Autoit :D

Just to point out, in order to use the button method, you could use a variable to save the last seleceted item, that way when you press the button, it reads from the $last_selected rather than the $listview. (if you really wanted the button method).

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...