E1M1 Posted April 7, 2012 Posted April 7, 2012 (edited) 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. expandcollapse popup#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 April 7, 2012 by E1M1 edited
E1M1 Posted April 7, 2012 Author Posted April 7, 2012 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. expandcollapse popup#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
Moderators Melba23 Posted April 7, 2012 Moderators Posted April 7, 2012 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: expandcollapse popup#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 E1M1 1 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
E1M1 Posted April 7, 2012 Author Posted April 7, 2012 Thank you very much. I didn't even know that I can use GUICtrlDelete(). edited
AUTTRY Posted August 8, 2012 Posted August 8, 2012 (edited) Modified a bit to avoid the delete operation for an empty array. expandcollapse popup#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 August 8, 2012 by AUTTRY
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now