Jump to content

Problem with removing tab item.


Recommended Posts

Hello

I am having strange problem with deleting tab item. When I create multiple tabs and then delete one of them then tabs right of deleted tabs will display wrong control on them.

Each tab created has Edit on it. Edit's data is number which is same as tab number. So TabSheet 1 will have Edit displaying 1 in it ... TabSheet 5 has Edit displaying 5 in it.

Problem: When I close TabSheet 1 so that TabSheet 2 gets first tab then it doesn't have edit control in it. And other tabs have offset by 1. So edit in TabSheet 5 shows you 4 not 5. Why does the rest of tabs show me wrong edit control after deleting tab? Would be great if someone could help me to find out what causes it and how I could fix that.

Note: during the testing you can use Ctrl+T and Ctrl+W to save your time.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <GuiTab.au3>
#include <Array.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Use Ctrl+T and CTRL+W to add/remove tabs", 625, 443, 192, 124)
$Tab1 = GUICtrlCreateTab(5, 30, 616, 406)
GUICtrlSetResizing(-1, $GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
GUICtrlCreateTabItem("")
$Add = GUICtrlCreateButton("Add", 5, 5, 75, 25, $WS_GROUP)
$Remove = GUICtrlCreateButton("Remove", 85, 5, 75, 25, $WS_GROUP)
Dim $Form1_AccelTable[2][2] = [["^t", $Add],["^w", $Remove]]
GUISetAccelerators($Form1_AccelTable)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


Dim $EDITS[1]

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

        Case $Add
            GUICtrlCreateTabItem("TabSheet " & UBound($EDITS))
            $EDITS[UBound($EDITS)-1]=GUICtrlCreateEdit(UBound($EDITS),7,55,610,370)
            ReDim $EDITS[UBound($EDITS)+1]
            GUICtrlCreateTabItem("")
        Case $Remove
            GUICtrlDelete($EDITS[GUICtrlRead($Tab1)])
            _GUICtrlTab_DeleteItem($Tab1, GUICtrlRead($Tab1))
            _ArrayDelete($EDITS,GUICtrlRead($Tab1))
    EndSwitch
WEnd

Edit: Looks like edit controls are tied to tab ID and if mess those IDs up by adding/removing tabs then Edit's tab ID won't get updated so what happens is that when tab ID change (if i delete TabSheet 1 then ID of TabSheet2 is 1, not 2 anymore.) but Edit's tab ID association doesn't change.

To fix it I would have to update Edit controls parent but how?

Edited by E1M1

edited

Link to comment
Share on other sites

I figured that _GUICtrlTab allows me to manually show/hide edit controls. Only question is: how to I detect of user has clicked on some tab? With old code I could do case $Tab1 but that code doesn't work with this code here.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <GuiTab.au3>
#include <Array.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Use Ctrl+T and CTRL+W to add/remove tabs", 625, 443, 192, 124)
$Tab1 = _GUICtrlTab_Create($Form1,5, 30, 616, 406)
GUICtrlSetResizing(-1, $GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
GUICtrlCreateTabItem("")
$Add = GUICtrlCreateButton("Add", 5, 5, 75, 25, $WS_GROUP)
$Remove = GUICtrlCreateButton("Remove", 85, 5, 75, 25, $WS_GROUP)
Dim $Form1_AccelTable[2][2] = [["^t", $Add],["^w", $Remove]]
GUISetAccelerators($Form1_AccelTable)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


Dim $EDITS[1]

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

        Case $Add
            _GUICtrlTab_InsertItem ($Tab1,_GUICtrlTab_GetItemCount($Tab1),"TabSheet " & UBound($EDITS))
            $EDITS[UBound($EDITS)-1]=GUICtrlCreateEdit(UBound($EDITS),7,55,610,370)
            ReDim $EDITS[UBound($EDITS)+1]
;~           GUICtrlCreateTabItem("")
        Case $Remove
;~           GUICtrlDelete($EDITS[GUICtrlRead($Tab1)])
            _GUICtrlTab_DeleteItem($Tab1, GUICtrlRead($Tab1))
;~           _ArrayDelete($EDITS,GUICtrlRead($Tab1))
        Case $Tab1
            MsgBox(0,0,0)
    EndSwitch
WEnd

edited

Link to comment
Share on other sites

  • Moderators

E1M1,

Mixing native and UDF functions is usually a recipe for tears. ;)

The native function you are using to create the tabitem returns a ControlID - so use that to delete it. This works fine for me: :)

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <GuiTab.au3>
#include <Array.au3>

$Form1 = GUICreate("Use Ctrl+T and CTRL+W to add/remove tabs", 625, 443, 192, 124)

$Tab1 = GUICtrlCreateTab(5, 30, 616, 406)
GUICtrlSetResizing(-1, $GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
GUICtrlCreateTabItem("")
$Add = GUICtrlCreateButton("Add", 5, 5, 75, 25, $WS_GROUP)
$Remove = GUICtrlCreateButton("Remove", 85, 5, 75, 25, $WS_GROUP)

Dim $Form1_AccelTable[2][2] = [["^t", $Add],["^w", $Remove]]
GUISetAccelerators($Form1_AccelTable)

GUISetState(@SW_SHOW)

; Log both tabitems AND edits
Global $TABS[1]
Global $EDITS[1]

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

        Case $Add
            ; Log both the tab AND the edit ControlID
            $TABS[UBound($TABS)-1]=GUICtrlCreateTabItem("TabSheet " & UBound($EDITS))
            $EDITS[UBound($EDITS)-1]=GUICtrlCreateEdit(UBound($EDITS),7,55,610,370)
            ; ReDim BOTH arrays
            ReDim $TABS[UBound($TABS)+1]
            ReDim $EDITS[UBound($EDITS)+1]
            GUICtrlCreateTabItem("")
        Case $Remove
            ; Read the tab index
            $iTab = GUICtrlRead($Tab1)
            ; Remove the tab AND the edit from the arrays
            _ArrayDelete($EDITS, $iTab)
            _ArrayDelete($EDITS,$iTab)
            ; Remove the tab
            GUICtrlDelete($TABS[$iTab])

    EndSwitch
WEnd

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

  • 4 months later...

Modified a bit to avoid the delete operation for an empty array.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <GuiTab.au3>
#include <Array.au3>
$Form1 = GUICreate("Use Ctrl+T and CTRL+W to add/remove tabs", 625, 443, 192, 124)
$Tab1 = GUICtrlCreateTab(5, 30, 616, 406)
GUICtrlSetResizing(-1, $GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
GUICtrlCreateTabItem("")
$Add = GUICtrlCreateButton("Add", 5, 5, 75, 25, $WS_GROUP)
$Remove = GUICtrlCreateButton("Remove", 85, 5, 75, 25, $WS_GROUP)
Dim $Form1_AccelTable[2][2] = [["^t", $Add],["^w", $Remove]]
GUISetAccelerators($Form1_AccelTable)
GUISetState(@SW_SHOW)
; Log both tabitems AND edits
Global $TABS, $EDITS
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Add
            ; Log both the tab AND the edit ControlID
            If Not IsArray($TABS) Then
                  Dim $TABS[1], $EDITS[1]
            Else
                  ; ReDim BOTH arrays
                  ReDim $TABS[UBound($TABS)+1]
                  ReDim $EDITS[UBound($EDITS)+1]
            EndIf
            $TABS[UBound($TABS)-1] = GUICtrlCreateTabItem("TabSheet " & UBound($TABS))
            $EDITS[UBound($EDITS)-1] = GUICtrlCreateEdit(UBound($EDITS), 7, 55, 610, 370)
            GUICtrlCreateTabItem("")
        Case $Remove
            If Not IsArray($TABS) Then ContinueLoop
            ; Read the tab index
            $iTab = GUICtrlRead($Tab1)
            ; Remove the tab
            GUICtrlDelete($TABS[$iTab])
            ; Remove the tab AND the edit from the arrays
            _ArrayDelete($TABS, $iTab)
            _ArrayDelete($EDITS, $iTab)
    EndSwitch
WEnd
Edited by AUTTRY
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...