Jump to content

context menu downt work on TabSheet 2 (but works on TabSheet 1)


Recommended Posts

I was working on tabbed window when I ran into problem that I cant find solution for. That TreeView has context menu. Problem: Context menu selections doesn't work when I switch to TabSheet 2 however it works again when I switch back to TabSheet 1.

To create new tabs go: Add servers -> all

If anyone have any idea how to fix it I greatly appreciate it.

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <TreeViewConstants.au3>
#include <StaticConstants.au3>
#include <Array.au3>
#Include <GuiTreeView.au3>

const $IP = 0
const $IS_ONLINE = 1
const $IS_SELECTED = 2
const $MENU_CONNECT = 3
const $MENU_SELECT = 4
const $ITEM_ID = 5
;[IP][IsOline][IsSelected][Menu connect][Menu select]
Dim $items[10][6]=[["192.168.1.100", true, false, 0, 0, 0], ["192.168.1.101", True, False, 0, 0, 0], ["192.168.1.102", True, false, 0, 0, 0],["192.168.1.103", True, False, 0, 0, 0],["192.168.1.104", True, false, 0, 0, 0],["192.168.1.105", false, False, 0, 0, 0],["192.168.1.106", false, false, 0, 0, 0],["192.168.1.107", False, False, 0, 0, 0],["192.168.1.108", False, false, 0, 0, 0],["192.168.1.109", False, false, 0, 0, 0]]

;[Selected List]
dim $TabID[1]

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("terminal", 811, 645, 192, 124, BitOR($WS_MAXIMIZEBOX,$WS_MINIMIZEBOX,$WS_SIZEBOX,$WS_THICKFRAME,$WS_SYSMENU,$WS_CAPTION,$WS_OVERLAPPEDWINDOW,$WS_TILEDWINDOW,$WS_POPUP,$WS_POPUPWINDOW,$WS_GROUP,$WS_TABSTOP,$WS_BORDER,$WS_CLIPSIBLINGS))
$Servers = GUICtrlCreateMenu("Add servers")
$AllServers = GUICtrlCreateMenuItem("All", $Servers)
$Options = GUICtrlCreateMenu("Options")
$Option = GUICtrlCreateMenuItem("Options", $Options)

$treeview = GUICtrlCreateTreeView(675, 0, 130, 621, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
GUICtrlSetResizing(-1, $GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKBOTTOM+$GUI_DOCKWIDTH)
$selected = GUICtrlCreateTreeViewItem("Selected", $treeview)
GUICtrlSetColor(-1, 0x0000C0)
$not_selected = GUICtrlCreateTreeViewItem("Not selected", $treeview)
GUICtrlSetColor(-1, 0x0000C0)
DrawList()

$Tab1 = GUICtrlCreateTab(0, 0, 674, 563)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT+$GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKBOTTOM+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)

GUICtrlCreateTabItem("")
$Edit1 = GUICtrlCreateEdit("", 1, 565, 670, 59)
GUICtrlSetData(-1, "Edit1")
GUICtrlSetResizing(-1, $GUI_DOCKLEFT+$GUI_DOCKRIGHT+$GUI_DOCKBOTTOM+$GUI_DOCKHEIGHT)

GUICtrlSetState($selected, BitOR($GUI_EXPAND, $GUI_DEFBUTTON))
GUICtrlSetState($not_selected, BitOR($GUI_EXPAND, $GUI_DEFBUTTON))

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$old_tab_index = -1
While 1
    $msg = GUIGetMsg()
    Switch $msg
        case -3
            Exit
        case $AllServers
            GUICtrlCreateTabItem("TabSheet "&UBound($TabID))
            $old_tab_index = GuiCtrlRead($Tab1)
            $selected_list =  SelectAll()
            $TabID[UBound($TabID)-1] = $selected_list
            ReDrawAllItem($selected_list)
            ReDim $TabID[UBound($TabID)+1]
        Case $Tab1
            $sel_array_new = $TabID[GuiCtrlRead($Tab1)]
            $TabID[$old_tab_index] = GetSelectInfo()
            ReDrawAllItem($sel_array_new)
            $old_tab_index = GuiCtrlRead($Tab1)
    EndSwitch
    If $msg <> 0 Then
        For $i = 0 To UBound($items) -1
            If $msg = $items[$i][$MENU_CONNECT] Then
                $items[$i][$IS_ONLINE] =  not $items[$i][$IS_ONLINE]
                ReDrawItem($i)
            EndIf
            If $msg = $items[$i][$MENU_SELECT] Then
                $items[$i][$IS_SELECTED] =  not $items[$i][$IS_SELECTED]
                ReDrawItem($i)
;~               MsgBox(0,0,0)
            EndIf
        Next
    EndIf
WEnd


Func ReDrawItem($index)
    _GUICtrlTreeView_Delete($treeview, $items[$index][$ITEM_ID])
    $item_parent = $not_selected
    $item_color = 0xcc0020
    $item_menu_select = "Select"
    $item_menu_connect = "Connect"
    If $items[$index][$IS_SELECTED] Then
        $item_parent = $selected
        $item_menu_select = "Unselect"
    EndIf
    If $items[$index][$IS_ONLINE] Then
        $item_color = 0x008020
        $item_menu_connect = "Disonnect"
    EndIf
    $items[$index][$ITEM_ID] = GUICtrlCreateTreeViewItem($items[$index][$IP], $item_parent)
    GUICtrlSetColor(-1, $item_color)
    $item_menu = GUICtrlCreateContextMenu($items[$index][$ITEM_ID])
    $items[$index][$MENU_SELECT] = GUICtrlCreateMenuItem($item_menu_select, $item_menu)
    $items[$index][$MENU_CONNECT] = GUICtrlCreateMenuItem($item_menu_connect, $item_menu)
EndFunc

Func DrawList()
    For $i = 0 To UBound($items) -1
        $item_parent = $not_selected
        $item_color = 0xcc0020
        $item_menu_select = "Select"
        $item_menu_connect = "Connect"
        If $items[$i][$IS_SELECTED] Then
            $item_parent = $selected
            $item_menu_select = "Unselect"
        EndIf
        If $items[$i][$IS_ONLINE] Then
            $item_color = 0x008020
            $item_menu_connect = "Disonnect"
        EndIf
        $items[$i][$ITEM_ID] = GUICtrlCreateTreeViewItem($items[$i][$IP], $item_parent)
        GUICtrlSetColor(-1, $item_color)
        $item_menu = GUICtrlCreateContextMenu($items[$i][$ITEM_ID])
        $items[$i][$MENU_SELECT] = GUICtrlCreateMenuItem($item_menu_select, $item_menu)
        $items[$i][$MENU_CONNECT] = GUICtrlCreateMenuItem($item_menu_connect, $item_menu)
    Next
EndFunc

Func ReDrawAllItem($selection)
    For $i = 0 To UBound($items) -1
        $SELECT = false
        If _ArrayFind($selection, $i) Then $SELECT = True
;~       If $i = 0 Then
;~           MsgBox(0,$SELECT,$items[$i][$IS_SELECTED])
;~           _ArrayDisplay($selection)
;~       EndIf
        If $SELECT <> $items[$i][$IS_SELECTED] Then
            $items[$i][$IS_SELECTED] = $SELECT
             _GUICtrlTreeView_Delete($treeview, $items[$i][$ITEM_ID])
            $item_parent = $not_selected
            $item_color = 0xcc0020
            $item_menu_select = "Select"
            $item_menu_connect = "Connect"
            If $items[$i][$IS_SELECTED] Then
                $item_parent = $selected
                $item_menu_select = "Unselect"
            EndIf
            If $items[$i][$IS_ONLINE] Then
                $item_color = 0x008020
                $item_menu_connect = "Disonnect"
            EndIf
            $items[$i][$ITEM_ID] = GUICtrlCreateTreeViewItem($items[$i][$IP], $item_parent)
            GUICtrlSetColor(-1, $item_color)
            $item_menu = GUICtrlCreateContextMenu($items[$i][$ITEM_ID])
            $items[$i][$MENU_SELECT] = GUICtrlCreateMenuItem($item_menu_select, $item_menu)
            $items[$i][$MENU_CONNECT] = GUICtrlCreateMenuItem($item_menu_connect, $item_menu)
        EndIf
    Next
EndFunc

Func GetSelectInfo()
    Dim $NewArray[1]
    $count = 0
    For $i = 0 To UBound($items) -1
        If $items[$i][$IS_SELECTED] Then
            $count += 1
            ReDim $NewArray[$count]
            $NewArray[$count-1] =  $i
        EndIf
    Next
    Return $NewArray
EndFunc

Func SelectAll()
    Dim $selection[UBound($items)]
    For $i = 0 To UBound($selection) -1
        $selection[$i] = $i
    Next
    Return $selection
EndFunc

Func _ArrayFind($array,$value)
    For $i = 0 To UBound($array) -1
        If $array[$i] = $value Then Return True
    Next
    Return False
EndFunc

edited

Link to comment
Share on other sites

  • Moderators

E1M1,

I cannot reproduce the problem - the TreeView context menu appears regardless of the Tab I have selected. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Yes the menu appears but when you click nothing happens.

Sofar I figured that if I comment ReDrawAllItem($selected_list) out I don't get that error.

When TabSheet 1 is active $msg Is 10 when I click on 192.168.1.100 but when tabsheet 2 is active $msg is -7 when I click on that IP. Makes me think that it's get's captured by tab or something

Edit: had to add GuiCtrlCreateTabItem("") because otherwise ReDrawAllItem tries to create menu on tab.

Offtopic: Shall I somehow trash context menu when I delete treeview item? Or does autoit automatically delete it if treeview item gets deleted?

Edited by E1M1

edited

Link to comment
Share on other sites

  • Moderators

E1M1,

The context menu works for me regardless of the tab selection. It does have problems at times with the first child under "Unselected", but it works on the other children with no problem for me. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

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