Jump to content

_GUICtrlListView_Create() Context Menu


Recommended Posts

If i use the regular GUICtrlCreateListView() the context menu works, but since I canot use those due to the requirements of my script, how do i get the following to work:

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

Global $State
$Gui = GUICreate("Test", 200, 200)
$ListView = _GUICtrlListView_Create($Gui, "Tickets", 5, 5, 190, 190)
_GUICtrlListView_SetExtendedListViewStyle ($ListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES,$LVS_EX_REGIONAL))
_GUICtrlListView_SetColumnWidth($ListView, 0, 90)
$Context0 = GUICtrlCreateContextMenu($ListView)
$Context1 = GUICtrlCreateMenuItem("Add New Item", $Context0)
$Context2 = GUICtrlCreateMenu("Delete", $Context0)
$Context3 = GUICtrlCreateMenuItem("Delete Checked Items", $Context2)
$Context4 = GUICtrlCreateMenuItem("Delete UnChecked Items", $Context2)
GUICtrlCreateMenuItem("", $Context2)
$Context5 = GUICtrlCreateMenuItem("Delete All Items", $Context2)
GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $Context1
            GUICtrlCreateListViewItem("New Item " & _GUICtrlListView_GetItemCount($ListView) + 1, $ListView)
        Case $Context3
            Local $ChkID = ""
            For $i = 0 To _GUICtrlListView_GetItemCount($ListView) -1
                If _GUICtrlListView_GetItemChecked($ListView, $i) Then $ChkID &= _GUICtrlListView_GetItemParam($ListView, $i) & "|"
            Next
            If StringTrimRight($ChkID, 1) <> "" Then
                Dim $SP = StringSplit(StringTrimRight($ChkID, 1), "|")
                For $i = 1 To $SP[0]
                    GuiCtrlDelete($SP[$i])
                Next
            EndIf
        Case $Context4
            Local $ChkID = ""
            For $i = 0 To _GUICtrlListView_GetItemCount($ListView) -1
                If Not _GUICtrlListView_GetItemChecked($ListView, $i) Then $ChkID &= _GUICtrlListView_GetItemParam($ListView, $i) & "|"
            Next
            If StringTrimRight($ChkID, 1) <> "" Then
                Dim $SP = StringSplit(StringTrimRight($ChkID, 1), "|")
                For $i = 1 To $SP[0]
                    GuiCtrlDelete($SP[$i])
                Next
            EndIf
        Case $Context5
            Do
                GuiCtrlDelete(_GUICtrlListView_GetItemParam($ListView, 0))
            Until _GUICtrlListView_GetItemCount($ListView) = 0
    EndSwitch
    DisEnDel()
WEnd

Func DisEnDel()
    If Not _GUICtrlListView_GetItemCount($ListView) And $State = 0 Then
        $State = 1
        For $i = $Context2 To $Context5
            GUICtrlSetState($i, $GUI_DISABLE)
        Next
    ElseIf _GUICtrlListView_GetItemCount($ListView) > 0 And $State = 1 Then
        $State = 0
        For $i = $Context2 To $Context5
            GUICtrlSetState($i, $GUI_ENABLE)
        Next
    EndIf
EndFunc

-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Link to comment
Share on other sites

Hi,

Have a look in the help file under under User "Defined Functions -> GuiMenu Management".

You should be able to find a resolve for your question there.

Cheers

Thanks for that; but the only thing i don't like about those functions, is that they are WINDOW specific, not control specific. I only want to create 2 options when a user right clicks on the _GUiCtrlListView_Create() menu item. With those functions, near as i can tell, it would create the menu for the ENTIRE window, which is not what i need.

-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Link to comment
Share on other sites

Thanks for that; but the only thing i don't like about those functions, is that they are WINDOW specific, not control specific. I only want to create 2 options when a user right clicks on the _GUiCtrlListView_Create() menu item. With those functions, near as i can tell, it would create the menu for the ENTIRE window, which is not what i need.

Nvm, i got it! haha, guess i have to read a bit better :D

-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

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