Glyph Posted July 25, 2009 Share Posted July 25, 2009 (edited) Case $savepro If GUICtrlRead($proname) <> "" And GUICtrlRead($protocol) <> "" Then _GUICtrlListView_AddItem($ProfilesView, GUICtrlRead($proname), 0) _GUICtrlListView_AddSubItem($ProfilesView, 0, GUICtrlRead($protocol), 1) EndIf Now, when I add 2 items the subitem for the first changes, but does not move the previous sub item down with the regular item. Example: Name | Protocol1 Name2 | It will leave the second sub item blank while changing the first subitem (which should have been moved down) Here's one way to fix my problem: _GUICtrlListView_AddSubItem($ProfilesView, 0, GUICtrlRead($protocol), $X) Which would add each sub item when in a loop. But, it makes me wonder why the first item moves while leaving its sub-item behind... Anyone else have this problem before? Edited July 25, 2009 by Glyph tolle indicium Link to comment Share on other sites More sharing options...
Authenticity Posted July 25, 2009 Share Posted July 25, 2009 Read the _GUICtrlListView_AddSubItem() parameters description. The second parameter should be a zero-based number representing the index of the item this new sub item is added to. You can achieve it easily, without knowing the current item index by using _GUICtrlListView_InsertItem() and then using the return value in the _GUICtrlListView_AddSubItem(). Link to comment Share on other sites More sharing options...
Glyph Posted July 25, 2009 Author Share Posted July 25, 2009 (edited) This additem() function automatically "shuffles down" the list (carrying the main items down one) With subitem() you have to do it manually. My question is: Can I have this automatically "shuffle down" the subitems like the regular items? I'm sorry if I did not make this clear enough in the first post. If there are any more questions, please ask. here is my code: expandcollapse popup#include <WindowsConstants.au3> #include <GUIConstantSex.au3> #include <GuiListView.au3> #include <GuiMenu.au3> Global Enum $idEdit, $idLoad, $idUnload, $idDelete $gui2 = GUICreate("Profile Manager", 280, 210, Default, Default, -1, BitOR(0x00000080, 0x00000100)) $ProfilesView = _GUICtrlListView_Create($gui2, "Profile|Protocol", 120, 10, 150, 190) _GUICtrlListView_SetExtendedListViewStyle($ProfilesView, BitOR(0x00000020, 0x00000001)) GUICtrlCreateLabel("Profile:", 10, 10, 75, 15) $proname = GUICtrlCreateInput("", 10, 25, 100, 20) $protocol = GUICtrlCreateCombo("Protocol", 10, 50, 100, 20) GUICtrlSetData($protocol, "CIN|IRC|OSCAR") $savepro = GUICtrlCreateButton("Save >", 10, 75, 100, 25) $editpro = GUICtrlCreateButton("Edit...", 10, 100, 100, 25) $delpro = GUICtrlCreateButton("Delete <", 10, 125, 100, 25) $loadpro = GUICtrlCreateButton("Load", 10, 150, 100, 25) $unpro = GUICtrlCreateButton("Unload", 10, 175, 100, 25) GUISetState(@SW_show, $gui2) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit Case $savepro If GUICtrlRead($proname) <> "" And GUICtrlRead($protocol) <> "" Then _GUICtrlListView_AddItem($ProfilesView, GUICtrlRead($proname), 0) _GUICtrlListView_AddSubItem($ProfilesView, 0, GUICtrlRead($protocol),1) EndIf Case $delpro ; EndSwitch WEnd Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo ;~ Local $tBuffer $hWndListView = $ProfilesView If Not IsHWnd($ProfilesView) Then $hWndListView = GUICtrlGetHandle($ProfilesView) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam) $text=_GUICtrlListView_GetItem($profilesview,DllStructGetData($tInfo, "Index")) MsgBox(0, "Doubleclick", "Index " & $text[3] & @CRLF & "Subitem " & DllStructGetData($tInfo, "SubItem")) GUICtrlSetData($proname,$text[3]) Case $NM_RCLICK ; Sent by a list-view control when the user clicks an item with the right mouse button $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam) ListView_RClick() Return 0 ; allow the default processing EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func ListView_RClick() Local $aHit $aHit = _GUICtrlListView_SubItemHitTest($ProfilesView) If ($aHit[0] <> -1) Then ; Create a standard popup menu ; -------------------- To Do -------------------- $hMenu = _GUICtrlMenu_CreatePopup() _GUICtrlMenu_AddMenuItem($hMenu, "Edit", $idEdit) _GUICtrlMenu_AddMenuItem($hMenu, "Delete", $idDelete) _GUICtrlMenu_AddMenuItem($hMenu, "Load", $idLoad) _GUICtrlMenu_AddMenuItem($hMenu, "Unload", $idUnload) ; ======================================================================== ; Shows how to capture the context menu selections ; ======================================================================== Switch _GUICtrlMenu_TrackPopupMenu($hMenu, $ProfilesView, -1, -1, 1, 1, 2) Case $idEdit _DebugPrint("Edit: " & StringFormat("Item, SubItem [%d, %d]", $aHit[0], $aHit[1])) Case $idDelete _GUICtrlListView_DeleteItem($ProfilesView, $aHit[0]) ;_DebugPrint("Delete: " & StringFormat("Item, SubItem [%d, %d]", $aHit[0], $aHit[1])) Case $idLoad _DebugPrint("Load: " & StringFormat("Item, SubItem [%d, %d]", $aHit[0], $aHit[1])) Case $idUnload _DebugPrint("Unload: " & StringFormat("Item, SubItem [%d, %d]", $aHit[0], $aHit[1])) EndSwitch _GUICtrlMenu_DestroyMenu($hMenu) EndIf EndFunc ;==>ListView_RClick Func _DebugPrint($s_text, $line = @ScriptLineNumber) ConsoleWrite( _ "!===========================================================" & @LF & _ "+======================================================" & @LF & _ "-->Line(" & StringFormat("%04d", $line) & "):" & @TAB & $s_text & @LF & _ "+======================================================" & @LF) EndFunc ;==>_DebugPrint If you save 2 profiles with random names, you'll see what I mean. Edited July 25, 2009 by Glyph tolle indicium Link to comment Share on other sites More sharing options...
Authenticity Posted July 25, 2009 Share Posted July 25, 2009 So you're looking for inserting item rather than adding it: _GUICtrlListView_InsertItem($ProfilesView, GUICtrlRead($proname), 0) Link to comment Share on other sites More sharing options...
Glyph Posted July 25, 2009 Author Share Posted July 25, 2009 So you're looking for inserting item rather than adding it: _GUICtrlListView_InsertItem($ProfilesView, GUICtrlRead($proname), 0) That took me a minute to realize what you meant. ;_GUICtrlListView_AddItem($ProfilesView, GUICtrlRead($proname), 0) _GUICtrlListView_InsertItem($ProfilesView, GUICtrlRead($proname), 0) _GUICtrlListView_AddSubItem($ProfilesView, 0, GUICtrlRead($protocol),1) Works! I had to play around with it because I had no idea what you meant. xD Unfortunately, I cannot explain exactly why it works. >.> tolle indicium Link to comment Share on other sites More sharing options...
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