Jump to content

Listview


Recommended Posts

Hi! Try this:

#include <GuiConstants.au3>
#include <GuiListView.au3>
#include <GuiMenu.au3>

$hGui = GUICreate("Test GUI", 300, 200)

$hListView = _GUICtrlListView_Create($hGui, "Item|SubItem", 10, 10, 280, 160, -1, $WS_EX_CLIENTEDGE)

_GUICtrlListView_SetExtendedListViewStyle($hListView, $LVS_EX_FULLROWSELECT)

_GUICtrlListView_AddItem($hListView, "Item1")
_GUICtrlListView_AddItem($hListView, "Item2")
_GUICtrlListView_AddItem($hListView, "Item3")

_GUICtrlListView_AddSubItem($hListView, 0, "SubItem1", 1)
_GUICtrlListView_AddSubItem($hListView, 1, "SubItem2", 1)
_GUICtrlListView_AddSubItem($hListView, 2, "SubItem3", 1)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
    Local $hWndListView, $tNMHDR, $hWndFrom, $iCode
    
    $hWndListView = $hListView
    If Not IsHWnd($hWndListView) Then $hWndListView = GUICtrlGetHandle($hListView)
    
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "HwndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    
    Switch $hWndFrom
    Case $hWndListView
        Switch $iCode
        Case $NM_RCLICK
            Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
            Local $iIndex = DllStructGetData($tInfo, "Index")
            If $iIndex <> -1 Then _ContextMenu($iIndex)
        EndSwitch
    EndSwitch
    
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func _ContextMenu($sIndex)
    Local $idDelete = 1000
    Local $iHotItem, $hMenu
    
    $iHotItem = _GUICtrlListView_GetHotItem($hListView)
    If $iHotItem = -1 Then Return False
    
    $hMenu = _GUICtrlMenu_CreatePopup()
    _GUICtrlMenu_AddMenuItem($hMenu, "Delete", $idDelete)
    
    Switch _GUICtrlMenu_TrackPopupMenu($hMenu, $hListView, -1, -1, 1, 1, 2)
    Case $idDelete
        _GUICtrlListView_DeleteItem($hListView, $sIndex)
    EndSwitch
    
    _GUICtrlMenu_DestroyMenu($hMenu)
EndFunc   ;==>_ContextMenu
:) Edited by rasim
Link to comment
Share on other sites

I am getting an error at this line:

$hListView = _GUICtrlListView_Create($hGui, "Item|SubItem", 10, 10, 280, 160, -1, $WS_EX_CLIENTEDGE)

says, Variable used without being declared under $WS_EX_CLIENTEDGE...

While Alive() {
	 DrinkWine();
}
AutoIt Programmer
Link to comment
Share on other sites

I am getting an error at this line:

$hListView = _GUICtrlListView_Create($hGui, "Item|SubItem", 10, 10, 280, 160, -1, $WS_EX_CLIENTEDGE)

says, Variable used without being declared under $WS_EX_CLIENTEDGE...

Read the help you'll find out what include you need for that, being your using the beta.

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

When I put it in my script nothing happens. I used GUICtrlCreateListView() instead of _GUICtrlListView_Create(). Is that the problem?

#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiMenu.au3>
#include <WindowsConstants.au3>

$hGui = GUICreate("Test GUI", 300, 200)

$hListView = GUICtrlCreateListView("Item|SubItem", 10, 10, 280, 160, -1, $WS_EX_CLIENTEDGE)

_GUICtrlListView_SetExtendedListViewStyle($hListView, $LVS_EX_FULLROWSELECT)

_GUICtrlListView_AddItem($hListView, "Item1")
_GUICtrlListView_AddItem($hListView, "Item2")
_GUICtrlListView_AddItem($hListView, "Item3")

_GUICtrlListView_AddSubItem($hListView, 0, "SubItem1", 1)
_GUICtrlListView_AddSubItem($hListView, 1, "SubItem2", 1)
_GUICtrlListView_AddSubItem($hListView, 2, "SubItem3", 1)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
    Local $hWndListView, $tNMHDR, $hWndFrom, $iCode

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

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "HwndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")

    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_RCLICK
                    Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
                    Local $iIndex = DllStructGetData($tInfo, "Index")
                    If $iIndex <> -1 Then _ContextMenu($iIndex)
            EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func _ContextMenu($sIndex)
    Local $idDelete = 1000
    Local $iHotItem, $hMenu

    $iHotItem = _GUICtrlListView_GetHotItem($hListView)
    If $iHotItem = -1 Then Return False

    $hMenu = _GUICtrlMenu_CreatePopup()
    _GUICtrlMenu_AddMenuItem($hMenu, "Delete", $idDelete)

    Switch _GUICtrlMenu_TrackPopupMenu($hMenu, GUICtrlGetHandle($hListView), -1, -1, 1, 1, 2)
        Case $idDelete
            _GUICtrlListView_DeleteItem(GUICtrlGetHandle($hListView), $sIndex)
    EndSwitch

    _GUICtrlMenu_DestroyMenu($hMenu)
EndFunc   ;==>_ContextMenu

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Hmm...try this:

#include <GuiConstants.au3>
#include <GuiListView.au3>
#include <GuiMenu.au3>

$hGui = GUICreate("Test GUI", 300, 200)

$hListView = GUICtrlCreateListView("Item|SubItem", 10, 10, 280, 160, -1, $WS_EX_CLIENTEDGE)
$hListView = GUICtrlGetHandle($hListView)

_GUICtrlListView_SetExtendedListViewStyle($hListView, $LVS_EX_FULLROWSELECT)

_GUICtrlListView_AddItem($hListView, "Item1")
_GUICtrlListView_AddItem($hListView, "Item2")
_GUICtrlListView_AddItem($hListView, "Item3")

_GUICtrlListView_AddSubItem($hListView, 0, "SubItem1", 1)
_GUICtrlListView_AddSubItem($hListView, 1, "SubItem2", 1)
_GUICtrlListView_AddSubItem($hListView, 2, "SubItem3", 1)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
    Local $tNMHDR, $hWndFrom, $iCode
    
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = DllStructGetData($tNMHDR, "HwndFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    
    Switch $hWndFrom
    Case $hListView
        Switch $iCode
        Case $NM_RCLICK
            Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
            Local $iIndex = DllStructGetData($tInfo, "Index")
            If $iIndex <> -1 Then _ContextMenu($iIndex)
        EndSwitch
    EndSwitch
    
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func _ContextMenu($sIndex)
    Local $idDelete = 1000
    Local $iHotItem, $hMenu
    
    $iHotItem = _GUICtrlListView_GetHotItem($hListView)
    If $iHotItem = -1 Then Return False
    
    $hMenu = _GUICtrlMenu_CreatePopup()
    _GUICtrlMenu_AddMenuItem($hMenu, "Delete", $idDelete)
    
    Switch _GUICtrlMenu_TrackPopupMenu($hMenu, $hListView, -1, -1, 1, 1, 2)
    Case $idDelete
        _GUICtrlListView_DeleteItem($hListView, $sIndex)
    EndSwitch
    
    _GUICtrlMenu_DestroyMenu($hMenu)
EndFunc   ;==>_ContextMenu
Link to comment
Share on other sites

Nope. I have two thoughts as to why this might not be working...

1) I don't actually create the listview items in the script, the user can input a name and press a button and it will become a listview item.

2) I set my listviews to always on top.

While Alive() {
	 DrinkWine();
}
AutoIt Programmer
Link to comment
Share on other sites

Nope. I have two thoughts as to why this might not be working...

1) I don't actually create the listview items in the script, the user can input a name and press a button and it will become a listview item.

2) I set my listviews to always on top.

Mine should work just fine for you, don't matter when the items are created or the z order

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

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