Syed23 Posted December 2, 2013 Posted December 2, 2013 (edited) Hi All, Good Day! i got a doubt in a below code. I am working on the project where i am using Tree view items. if i select any of the tree view item i wanted to display the name of the selected item. but the Function _GUICtrlTreeView_HitTestItem() is returng 0 value. i spent almost 8 hours on this figure out myself but couldn't . Can some one help me on this please? expandcollapse popup#include <GUIConstants.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> #include <GuiTreeView.au3> #include <TreeViewConstants.au3> Global $hTreeView #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("BVAdmin", 806, 443, -1, -1) GUISetBkColor(0xFFFFFF) $Menu1 = GUICtrlCreateMenu("Load") $Menu2 = GUICtrlCreateMenu("Save") $ItemApp = GUICtrlCreateMenuItem("Application", $Menu1) $ItemReg = GUICtrlCreateMenuItem("Reg Files", $Menu1) $ItemCust = GUICtrlCreateMenuItem("Custom Files", $Menu1) $ItemSave = GUICtrlCreateMenuItem("Save", $Menu2) $Itemexit = GUICtrlCreateMenuItem("Exit", $Menu2) $Group = GUICtrlCreateGroup("List", 5, 10, 210, 400) $Group1 = GUICtrlCreateGroup("Data", 260, 10, 530, 200) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() If $nMsg = $GUI_EVENT_CLOSE Then Exit EndIf If $nMsg = $ItemApp Then list() EndIf If $nMsg = $GUI_EVENT_PRIMARYDOWN Then Local $tMPos = _WinAPI_GetMousePos (True, $hTreeView) Local $tHitTest = _GUICtrlTreeView_HitTestEx ($hTreeView, DllStructGetData($tMPos, 1), DllStructGetData($tMPos, 2)) Local $iFlags = DllStructGetData($tHitTest, "Flags") Select Case $iFlags Local $hItem = _GUICtrlTreeView_HitTestItem ($hTreeView, DllStructGetData($tMPos, 1), DllStructGetData($tMPos, 2)) Local $fChecked = False MsgBox(0,"",$hItem) If _GUICtrlTreeView_GetSelected ($hTreeView, $hItem) Then $fChecked = True _TvCheckbox($hItem, $fChecked) EndSelect EndIf WEnd Func list() $hTreeView = GUICtrlCreateTreeView(20, 30, 180, 380) For $i = 1 To 10 GUICtrlCreateTreeViewItem($i, $hTreeView) Next EndFunc ;==>list Func _TvCheckbox($hItem, $fChecked) MsgBox(0, "", $hItem & @CRLF & @CRLF & @CRLF & @CRLF & @CRLF & @CRLF & $fChecked) EndFunc ;==>_TvCheckbox Func WM_NOTIFY($hWnd, $msg, $wParam, $lParam) Local $tNMHDR, $IdFrom, $iCode $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $IdFrom = DllStructGetData($tNMHDR, "IdFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hTreeView Switch $iCode Case $NM_CLICK $fDblClk = True EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Edited December 2, 2013 by Syed23 Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]
Moderators Melba23 Posted December 3, 2013 Moderators Posted December 3, 2013 Syed23,You were overcomplicating it horribly:While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $ItemApp list() Case $GUI_EVENT_PRIMARYDOWN ; Set mouse coord mode to active window client area $iOldOpt = Opt("MouseCoordMode", 2) Local $aMpos = MouseGetPos() ; Adjust for position of TreeView within client area Local $hItem = _GUICtrlTreeView_HitTestItem($hTreeView, $aMpos[0] - 20, $aMpos[1] - 30) ; Reset mous coord mode Opt("MouseCoordMode", $iOldOpt) Local $sText = _GUICtrlTreeView_GetText($hTreeView, $hItem) Local $fChecked = False If _GUICtrlTreeView_GetSelected($hTreeView, $hItem) Then $fChecked = True _TvCheckbox($sText, $fChecked) EndSwitch WEndAnd I am surprised that you have not yet switched (pun intended) from multiple If...EndIf statements in your idle loop - I think the example code is much clearer. As usual, do ask if you have any questions. M23 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
Syed23 Posted December 3, 2013 Author Posted December 3, 2013 Hi Melba23, Thank you so much . As always i got an excellent help from you in quick fashion.. you are a star! i got couple of question to understand myself in the above example you showed. $GUI_EVENT_PRIMARYDOWN - What is this action variable meant for ? _GUICtrlTreeView_HitTestItem($hTreeView, $aMpos[0] - 20, $aMpos[1] - 30) - Why we are doing minus 20 and minus 30 with Xaxis and Yaxis? After the above line why we are resetting the mouse coord mode? Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]
Moderators Melba23 Posted December 3, 2013 Moderators Posted December 3, 2013 (edited) Syed23, $GUI_EVENT_PRIMARYDOWN - What is this action variable meant for ?It is the Windows code for the event caused by pressing the primary (usually left) mouse button. Why we are doing minus 20 and minus 30 with Xaxis and Yaxis?Because the HitTest coordinates need to be relative to the TreeView. By default, MouseGetPos returns screen coordinates - by changing the "MouseCoordMode" to the client area of the GUI we get part of the way there, but we still need to correct for the posiiton of the TreeView within the GUI (it was created at (20, 30). why we are resetting the mouse coord mode?Because as I explained above, the default mode is for MouseGetPos to return screen coordinates. If we changed the mode and left it, other sections of the script might not work correctly as the coordinates they used would be incorrect. Of couse if this turns out to be the only place in the script that uses mouse coordinates then you can change the mode at the top of the script and leave it.All clear now? M23Edit: 18k! Edited December 3, 2013 by Melba23 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
Syed23 Posted December 3, 2013 Author Posted December 3, 2013 Hi Melba23, Yeah.. got cleared .. 18k ? is the payment ? Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]
Moderators Melba23 Posted December 3, 2013 Moderators Posted December 3, 2013 Syed23,No, the help is free as always. The edit was because I noticed my post count at that time had a more few zeroes than normal. M23 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
Syed23 Posted December 3, 2013 Author Posted December 3, 2013 oopss..... sorry for that .. i did not notice the count... now you are in 18,002.... Excellent milestone! Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]
Syed23 Posted December 3, 2013 Author Posted December 3, 2013 Hi Melba23, Sorry to bother you! in the below code after i select the tree view i am displaying List view item on the side with information. if i change the selection on tree view and it shows fine in listview but if i click on list view window then the values getting changed to the first selection of the tree value. i don't understand the logic how it happens. can you help me please? expandcollapse popup#include <GUIConstants.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> #include <GuiTreeView.au3> #include <TreeViewConstants.au3> #include <GuiListView.au3> #include <ListviewConstants.au3> #include <GuiComboBox.au3> Global $hTreeView #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("BVAdmin", 906, 343, -1, -1) GUISetBkColor(0xFFFFFF) $Menu1 = GUICtrlCreateMenu("Load") $Menu2 = GUICtrlCreateMenu("Save") $ItemApp = GUICtrlCreateMenuItem("Application", $Menu1) $ItemReg = GUICtrlCreateMenuItem("Reg Files", $Menu1) $ItemCust = GUICtrlCreateMenuItem("Custom Files", $Menu1) $ItemSave = GUICtrlCreateMenuItem("Save", $Menu2) $Itemexit = GUICtrlCreateMenuItem("Exit", $Menu2) $Group = GUICtrlCreateGroup("List", 5, 10, 210, 300) $Group1 = GUICtrlCreateGroup("Data", 260, 10, 630, 200) $AddButton = GUICtrlCreateButton("",280,190,40,45) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") #EndRegion ### END Koda GUI section ### While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $ItemApp list() Case $GUI_EVENT_PRIMARYDOWN ; Set mouse coord mode to active window client area $iOldOpt = Opt("MouseCoordMode", 2) Local $aMpos = MouseGetPos() ; Adjust for position of TreeView within client area Local $hItem = _GUICtrlTreeView_HitTestItem ($hTreeView, $aMpos[0] - 20, $aMpos[1] - 30) ; Reset mous coord mode Opt("MouseCoordMode", $iOldOpt) Local $sText = _GUICtrlTreeView_GetText ($hTreeView, $hItem) Local $fChecked = False If _GUICtrlTreeView_GetSelected ($hTreeView, $hItem) Then $fChecked = True _TvCheckbox($sText, $fChecked) EndSwitch WEnd Func list() $hTreeView = GUICtrlCreateTreeView(20, 30, 180, 270) For $i = 1 To 10 GUICtrlCreateTreeViewItem($i, $hTreeView) Next EndFunc ;==>list Func _TvCheckbox($hItem, $fChecked) If $fChecked = True Then $hListview = GUICtrlCreateListView("Name|Location|Appversion", 270, 30, 600, 160) ;_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_GRIDLINES)) _GUICtrlListView_SetColumnWidth($hListView, 0, 200) _GUICtrlListView_SetColumnWidth($hListView, 1, 220) _GUICtrlListView_SetColumnWidth($hListView, 2, $LVSCW_AUTOSIZE_USEHEADER ) $hListViewItem = GUICtrlCreateListViewItem($hItem&"|"&$hItem&"|"&$hItem,$hListview) EndIf EndFunc ;==>_TvCheckbox Func WM_NOTIFY($hWnd, $msg, $wParam, $lParam) Local $tNMHDR, $IdFrom, $iCode $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $IdFrom = DllStructGetData($tNMHDR, "IdFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hTreeView Switch $iCode Case $NM_CLICK $fDblClk = True EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]
Moderators Melba23 Posted December 3, 2013 Moderators Posted December 3, 2013 Syed23,You were firing the $GUI_EVENT_PRIMARYDOWN event when you clicked on the ListView and so resetting the content as if teh TreeView had been clicked. I notice now that you were recreating the ListView each time you fired the _TvCheckbox function. Best to create both the treeView and ListView just the once like this:expandcollapse popup#include <GUIConstants.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> #include <GuiTreeView.au3> #include <TreeViewConstants.au3> #include <GuiListView.au3> #include <ListviewConstants.au3> #include <GuiComboBox.au3> Global $hTreeView, $hListView $Form1 = GUICreate("BVAdmin", 906, 343, -1, -1) GUISetBkColor(0xFFFFFF) $Menu1 = GUICtrlCreateMenu("Load") $Menu2 = GUICtrlCreateMenu("Save") $ItemApp = GUICtrlCreateMenuItem("Application", $Menu1) $ItemReg = GUICtrlCreateMenuItem("Reg Files", $Menu1) $ItemCust = GUICtrlCreateMenuItem("Custom Files", $Menu1) $ItemSave = GUICtrlCreateMenuItem("Save", $Menu2) $Itemexit = GUICtrlCreateMenuItem("Exit", $Menu2) $Group = GUICtrlCreateGroup("List", 5, 10, 210, 300) $hTreeView = GUICtrlCreateTreeView(20, 30, 180, 270) $Group1 = GUICtrlCreateGroup("Data", 260, 10, 630, 200) $hListview = GUICtrlCreateListView("Name|Location|Appversion", 270, 30, 600, 160) ;_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_GRIDLINES)) _GUICtrlListView_SetColumnWidth($hListview, 0, 200) _GUICtrlListView_SetColumnWidth($hListview, 1, 220) _GUICtrlListView_SetColumnWidth($hListview, 2, $LVSCW_AUTOSIZE_USEHEADER) $AddButton = GUICtrlCreateButton("", 280, 190, 40, 45) $cClick_TV = GUICtrlCreateDummy() $cClick_LV = GUICtrlCreateDummy() GUISetState(@SW_SHOW) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $ItemApp list() Case $cClick_TV ; Set mouse coord mode to active window client area $iOldOpt = Opt("MouseCoordMode", 2) Local $aMpos = MouseGetPos() ; Adjust for position of TreeView within client area Local $hItem = _GUICtrlTreeView_HitTestItem($hTreeView, $aMpos[0] - 20, $aMpos[1] - 30) ; Reset mous coord mode Opt("MouseCoordMode", $iOldOpt) Local $sText = _GUICtrlTreeView_GetText($hTreeView, $hItem) Local $fChecked = False If _GUICtrlTreeView_GetSelected($hTreeView, $hItem) Then $fChecked = True _TvCheckbox($sText, $fChecked) Case $cClick_LV MsgBox(0, "Hi", "ListView clicked") EndSwitch WEnd Func list() For $i = 1 To 10 GUICtrlCreateTreeViewItem($i, $hTreeView) Next EndFunc ;==>list Func _TvCheckbox($hItem, $fChecked) If $fChecked = True Then $hListViewItem = GUICtrlCreateListViewItem($hItem & "|" & $hItem & "|" & $hItem, $hListview) EndIf EndFunc ;==>_TvCheckbox Func WM_NOTIFY($hWnd, $msg, $wParam, $lParam) Local $tNMHDR, $IdFrom, $iCode $tNMHDR = DllStructCreate($tagNMHDR, $lParam) ;$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $IdFrom = DllStructGetData($tNMHDR, "IdFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $iCode Case $NM_CLICK ConsoleWrite($IdFrom & @CRLF) Switch $IdFrom Case $hTreeView GUICtrlSendToDummy($cClick_TV) Case $hListview GUICtrlSendToDummy($cClick_LV) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFYNote how I have differentiated in the handler between where the clicks are made and used 2 dummy controls to fire the correct event. Please ask if you have any questions. M23 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
Syed23 Posted December 3, 2013 Author Posted December 3, 2013 ah... i did not know that ... Thank you so much Melba23... Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]
Syed23 Posted December 9, 2013 Author Posted December 9, 2013 (edited) Hi Melba23, With your help i have added few more lines to the code where if i click edit button i am trying to bring the edit window to modify the content of the listbox. what i am failing to do is, i am able to edit only one column.. can you guide me how to enable edit window for all the columns of the listview? for example if i have 5 columns when i click edit button all the 5 columns should show me the edit window. is that possible to do? i think i need to just adjust the bit code to make it work.. am i right? Here is my code: expandcollapse popup#include <GUIConstants.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> #include <GuiTreeView.au3> #include <TreeViewConstants.au3> #include <GuiListView.au3> #include <ListviewConstants.au3> #include <GuiComboBox.au3> #include <Misc.au3> #include <GuiListBox.au3> #include <EditConstants.au3> #include <GuiEdit.au3> #include <UpdownConstants.au3> #include <ButtonConstants.au3> #include <_ProgressSetMarquee.au3> Global $iWidth = 210, $iHeight = 20, $iLeft = 10, $iTop = 10 ; <<<<< Change Values here. Global $hTreeView, $hListView, $hItem, $hBrush, $Progress, $hListViewItem, $iCount = 0,$hEdit,$Item,$iText,$SubItem,$hDC Global $Style = BitOR($WS_CHILD, $WS_VISIBLE, $ES_AUTOHSCROLL, $ES_LEFT) $Form1 = GUICreate("BVAdmin", 1000, 343, -1, -1) GUISetBkColor(0xFFFFFF) $Menu1 = GUICtrlCreateMenu("Load") $Menu2 = GUICtrlCreateMenu("Save") $ItemApp = GUICtrlCreateMenuItem("Application", $Menu1) $ItemReg = GUICtrlCreateMenuItem("Reg Files", $Menu1) $ItemCust = GUICtrlCreateMenuItem("Custom Files", $Menu1) $ItemSave = GUICtrlCreateMenuItem("Save", $Menu2) $Itemexit = GUICtrlCreateMenuItem("Exit", $Menu2) $Group = GUICtrlCreateGroup("List", 5, 10, 210, 300) $hTreeView = GUICtrlCreateTreeView(20, 30, 180, 270) $Group1 = GUICtrlCreateGroup("Data", 240, 10, 750, 180) $AddButton = GUICtrlCreateButton("Add", 270, 160, 40, 30, $BS_ICON) GUICtrlSetState(-1, $GUI_HIDE) GUICtrlSetTip(-1, "Allows you to Add new Entry to the list") ;GUICtrlSetColor($AddButton,0x0B610B) $EditButton = GUICtrlCreateButton("Edit", 320, 160, 40, 30, $BS_ICON) ;GUICtrlSetState(-1,$GUI_DISABLE) ;GUICtrlSetColor($EditButton,0x0000FF) GUICtrlSetState(-1, $GUI_HIDE) GUICtrlSetTip(-1, "Allows you to Edit ListBox") $CancelButton = GUICtrlCreateButton("Cancel", 370, 160, 40, 30, $BS_ICON) GUICtrlSetState(-1, $GUI_HIDE) GUICtrlSetTip(-1, "Allows you to Cancel the Editing mode") ;GUICtrlSetState(-1,$GUI_DISABLE) ;GUICtrlSetColor($CancelButton,0xff0000) $DelectButton = GUICtrlCreateButton("Delete", 420, 160, 40, 30) GUICtrlSetColor(-1, 0xFF0000) GUICtrlSetState(-1, $GUI_HIDE) GUICtrlSetTip(-1, "Allows you to Delete the Entry from the list") ;GUICtrlSetState(-1,$GUI_DISABLE) ;GUICtrlSetColor($DelectButton,0xff0000) $ProgLabel = GUICtrlCreateLabel("Accessing Database...", 600, 255, 150, 50) $Progress_1 = GUICtrlCreateProgress(750, 250, 220, 20, 0x0008) ; 0x0008 = $PBS_MARQUEE From <ProgressConstants.au3> _ProgressSetTheme() _ProgressSetMarquee($Progress_1, $Form1) $cClick_TV = GUICtrlCreateDummy() $cClick_LV = GUICtrlCreateDummy() GUISetState(@SW_SHOW) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $ItemApp GUICtrlSetState($AddButton, $GUI_SHOW) $App = True $Reg = False $Cust = False _GUICtrlTreeView_DeleteAll($hTreeView) _GUICtrlListView_DeleteAllItems($hListView) list() Case $ItemReg GUICtrlSetState($AddButton, $GUI_SHOW) $App = False $Reg = True $Cust = False _GUICtrlTreeView_DeleteAll($hTreeView) _GUICtrlListView_DeleteAllItems($hListView) Reg() Case $ItemCust GUICtrlSetState($AddButton, $GUI_SHOW) $App = False $Reg = False $Cust = True _GUICtrlTreeView_DeleteAll($hTreeView) _GUICtrlListView_DeleteAllItems($hListView) Cust() Case $AddButton ADDButton() Case $DelectButton DeleteButton() Case $EditButton Edit() Case $cClick_TV ; Set mouse coord mode to active window client area $iOldOpt = Opt("MouseCoordMode", 2) Local $aMpos = MouseGetPos() ; Adjust for position of TreeView within client area Local $hItem = _GUICtrlTreeView_HitTestItem($hTreeView, $aMpos[0] - 20, $aMpos[1] - 30) ; Reset mous coord mode Opt("MouseCoordMode", $iOldOpt) Local $sText = _GUICtrlTreeView_GetText($hTreeView, $hItem) Local $fChecked = False If _GUICtrlTreeView_GetSelected($hTreeView, $hItem) Then $fChecked = True _TvCheckbox($sText, $fChecked) Case $cClick_LV ; MsgBox(0, "Hi", "ListView clicked") EndSwitch WEnd Func list() listcreate() For $i = 1 To 10 GUICtrlCreateTreeViewItem($i, $hTreeView) Next EndFunc ;==>list Func Reg() listcreate() For $i = 100 To 110 GUICtrlCreateTreeViewItem($i, $hTreeView) Next EndFunc ;==>Reg Func Cust() listcreate() For $i = 200 To 210 GUICtrlCreateTreeViewItem($i, $hTreeView) Next EndFunc ;==>Cust Func ADDButton() $TreeCount = _GUICtrlTreeView_GetCount($hTreeView) Do $AddInput = InputBox("BVAdmin", "Enter the Application Name") Until $AddInput <> "" GUICtrlCreateTreeViewItem($AddInput, $hTreeView) EndFunc ;==>ADDButton Func DeleteButton() _GUICtrlTreeView_Delete($hTreeView, $hItem) _GUICtrlListView_DeleteItem($hListView, 0) EndFunc ;==>DeleteButton Func Edit() Local $aHit = _GUICtrlListView_SubItemHitTest($hListView) If ($aHit[0] <> -1) And ($aHit[1] = 0) Then $Item = $aHit[0] $SubItem = 0 Local $aRect = _GUICtrlListView_GetItemRect($hListView, $Item) ElseIf ($aHit[0] <> -1) And ($aHit[1] > 0) Then $Item = $aHit[0] $SubItem = $aHit[1] EndIf Local $aRect = _GUICtrlListView_GetSubItemRect($hListView, $Item, $SubItem) Local $iItemText = _GUICtrlListView_GetItemText($hListView, 0) Local $iLen = _GUICtrlListView_GetStringWidth($hListView, $iItemText) ;$hEdit = _GUICtrlEdit_Create ($Form1, $iItemText, $aRect[0] + 3, $aRect[1], $iLen + 10, 17, $Style) $hEdit = _GUICtrlEdit_Create($Form1, $iItemText, $aRect[0] + 265, $aRect[1]+60 , $iLen + 90, 17, $Style) _GUICtrlEdit_SetSel($hEdit, 0, -1) _WinAPI_SetFocus($hEdit) $hDC = _WinAPI_GetWindowDC($hEdit) $hBrush = _WinAPI_CreateSolidBrush(0x0000FF) FrameRect($hDC, 0, 0, $iLen + 10, 17, $hBrush) Return $GUI_RUNDEFMSG EndFunc ;==>Edit Func listcreate() _GUICtrlListView_Destroy($hListView) If $App = True Then $hListView = GUICtrlCreateListView("Name|Location|Appversion|RegionID|App Type", 260, 30, 720, 80, $LVS_EDITLABELS) _GUICtrlListView_SetColumnWidth($hListView, 0, 200) _GUICtrlListView_SetColumnWidth($hListView, 1, 220) _GUICtrlListView_SetColumnWidth($hListView, 2, 100) _GUICtrlListView_SetColumnWidth($hListView, 3, 70) _GUICtrlListView_SetColumnWidth($hListView, 4, $LVSCW_AUTOSIZE_USEHEADER) ElseIf $Reg = True Then $hListView = GUICtrlCreateListView("Name|Location|Keypath|Value|Mode", 260, 30, 720, 80, $LVS_EDITLABELS) _GUICtrlListView_SetColumnWidth($hListView, 0, 200) _GUICtrlListView_SetColumnWidth($hListView, 1, 220) _GUICtrlListView_SetColumnWidth($hListView, 2, 200) _GUICtrlListView_SetColumnWidth($hListView, 3, 50) _GUICtrlListView_SetColumnWidth($hListView, 4, $LVSCW_AUTOSIZE_USEHEADER) ElseIf $Cust = True Then $hListView = GUICtrlCreateListView("Name|Location", 260, 30, 720, 80, $LVS_EDITLABELS) _GUICtrlListView_SetColumnWidth($hListView, 0, 200) _GUICtrlListView_SetColumnWidth($hListView, 1, $LVSCW_AUTOSIZE_USEHEADER) EndIf EndFunc ;==>listcreate Func _TvCheckbox($hItem, $fChecked) If $App = True Then If $fChecked = True Then GUICtrlSetState($EditButton, $GUI_SHOW) GUICtrlSetState($CancelButton, $GUI_SHOW) GUICtrlSetState($DelectButton, $GUI_SHOW) _GUICtrlListView_DeleteAllItems($hListView) $hListViewItem = GUICtrlCreateListViewItem($hItem & "|" & $hItem & "|" & $hItem & "|" & $hItem & "|" & $hItem, $hListView) EndIf ElseIf $Reg = True Then GUICtrlSetState($EditButton, $GUI_SHOW) GUICtrlSetState($CancelButton, $GUI_SHOW) GUICtrlSetState($DelectButton, $GUI_SHOW) _GUICtrlListView_DeleteAllItems($hListView) $hListViewItem = GUICtrlCreateListViewItem($hItem & "|" & $hItem & "|" & $hItem & "|" & $hItem & "|" & $hItem, $hListView) ElseIf $Cust = True Then GUICtrlSetState($EditButton, $GUI_SHOW) GUICtrlSetState($CancelButton, $GUI_SHOW) GUICtrlSetState($DelectButton, $GUI_SHOW) _GUICtrlListView_DeleteAllItems($hListView) $hListViewItem = GUICtrlCreateListViewItem($hItem & "|" & $hItem, $hListView) EndIf EndFunc ;==>_TvCheckbox Func WM_NOTIFY($hWnd, $msg, $wParam, $lParam) Local $tNMHDR, $IdFrom, $iCode $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $IdFrom = DllStructGetData($tNMHDR, "IdFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $iCode Case $NM_CLICK ConsoleWrite($IdFrom & @CRLF) Switch $IdFrom Case $hTreeView GUICtrlSendToDummy($cClick_TV) Case $hListView GUICtrlSendToDummy($cClick_LV) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func FrameRect($hDC, $nLeft, $nTop, $nRight, $nBottom, $hBrush) Local $stRect = DllStructCreate("int;int;int;int") DllStructSetData($stRect, 1, $nLeft) DllStructSetData($stRect, 2, $nTop) DllStructSetData($stRect, 3, $nRight) DllStructSetData($stRect, 4, $nBottom) DllCall("user32.dll", "int", "FrameRect", "hwnd", $hDC, "ptr", DllStructGetPtr($stRect), "hwnd", $hBrush) EndFunc ;==>FrameRect Func WM_COMMAND($hWnd, $msg, $wParam, $lParam) Local $iCode = BitShift($wParam, 16) Switch $lParam Case $hEdit Switch $iCode Case $EN_KILLFOCUS Local $iText = _GUICtrlEdit_GetText($hEdit) _GUICtrlListView_SetItemText($hListView, $Item, $iText, $SubItem) _WinAPI_DeleteObject($hBrush) _WinAPI_ReleaseDC($hEdit, $hDC) _WinAPI_DestroyWindow($hEdit) $Item = -1 $SubItem = 0 EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_COMMAND Thanks in advance! Edited: Added the script Edited December 9, 2013 by Syed23 Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]
Moderators Melba23 Posted December 10, 2013 Moderators Posted December 10, 2013 Syed23,if i have 5 columns when i click edit button all the 5 columns should show me the edit window. is that possible to do?Yes, look at my GUIListViewEx UDF. M23 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
Syed23 Posted December 10, 2013 Author Posted December 10, 2013 Wow.... that has lot of information what i needed... Thank you so much Melba23.. Before i post any question regarding Listview on the forum i will try with your ListviewEx function for reference.. that has all what required ...once again Thank you so much Melba23. Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]
Syed23 Posted December 10, 2013 Author Posted December 10, 2013 (edited) Hi Melba23, I tried by adding your function in my script.. but something i am doing wrong which causing to make the tool work with edit option. could you please help me on this? i have added the code below which i tried. expandcollapse popup#include <GUIConstants.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> #include <GuiTreeView.au3> #include <TreeViewConstants.au3> #include <GuiListView.au3> #include <ListviewConstants.au3> #include <GuiComboBox.au3> #include <Misc.au3> #include <GuiListBox.au3> #include <EditConstants.au3> #include <GuiEdit.au3> #include <UpdownConstants.au3> #include <ButtonConstants.au3> #include <_ProgressSetMarquee.au3> #include "GUIListViewEx.au3" FileInstall("C:\Users\Q03200\Desktop\ICONS\Semlabs-Web-Blog-Add.ico", @TempDir & "\Semlabs-Web-Blog-Add.ico", 1) FileInstall("C:\Users\Q03200\Desktop\ICONS\Creative-Freedom-Free-Funktional-05-Edit.ico", @TempDir & "\Creative-Freedom-Free-Funktional-05-Edit.ico", 1) FileInstall("C:\Users\Q03200\Desktop\ICONS\Fatcow-Farm-Fresh-Bullet-delete.ico", @TempDir & "\Fatcow-Farm-Fresh-Bullet-delete.ico", 1) Global $iWidth = 210, $iHeight = 20, $iLeft = 10, $iTop = 10 ; <<<<< Change Values here. Global $hTreeView, $hListView, $hItem, $hBrush, $Progress, $hListViewItem, $iCount = 0,$hEdit,$Item,$iText,$SubItem,$hDC,$iEditMode = 0 Global $Style = BitOR($WS_CHILD, $WS_VISIBLE, $ES_AUTOHSCROLL, $ES_LEFT) $Form1 = GUICreate("BVAdmin", 1000, 343, -1, -1) GUISetBkColor(0xFFFFFF) $Menu1 = GUICtrlCreateMenu("Load") $Menu2 = GUICtrlCreateMenu("Save") $ItemApp = GUICtrlCreateMenuItem("Application", $Menu1) $ItemReg = GUICtrlCreateMenuItem("Reg Files", $Menu1) $ItemCust = GUICtrlCreateMenuItem("Custom Files", $Menu1) $ItemSave = GUICtrlCreateMenuItem("Save", $Menu2) $Itemexit = GUICtrlCreateMenuItem("Exit", $Menu2) $Group = GUICtrlCreateGroup("List", 5, 10, 210, 300) $hTreeView = GUICtrlCreateTreeView(20, 30, 180, 270) $Group1 = GUICtrlCreateGroup("Data", 240, 10, 750, 180) $AddButton = GUICtrlCreateButton("", 270, 160, 40, 30, $BS_ICON) GUICtrlSetImage(-1, @TempDir & "\Semlabs-Web-Blog-Add.ico", -1, 0) GUICtrlSetState(-1, $GUI_HIDE) GUICtrlSetTip(-1, "Allows you to Add new Entry to the list") ;GUICtrlSetColor($AddButton,0x0B610B) $EditButton = GUICtrlCreateButton("", 320, 160, 40, 30, $BS_ICON) ;GUICtrlSetState(-1,$GUI_DISABLE) ;GUICtrlSetColor($EditButton,0x0000FF) GUICtrlSetImage($EditButton, @TempDir & "\Creative-Freedom-Free-Funktional-05-Edit.ico", -1, 0) GUICtrlSetState(-1, $GUI_HIDE) GUICtrlSetTip(-1, "Allows you to Edit ListBox") $CancelButton = GUICtrlCreateButton("", 370, 160, 40, 30, $BS_ICON) GUICtrlSetImage($CancelButton, @TempDir & "\Fatcow-Farm-Fresh-Bullet-delete.ico", -1, 0) GUICtrlSetState(-1, $GUI_HIDE) GUICtrlSetTip(-1, "Allows you to Cancel the Editing mode") ;GUICtrlSetState(-1,$GUI_DISABLE) ;GUICtrlSetColor($CancelButton,0xff0000) $DelectButton = GUICtrlCreateButton("X", 420, 160, 40, 30) GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0xFF0000) GUICtrlSetState(-1, $GUI_HIDE) GUICtrlSetTip(-1, "Allows you to Delete the Entry from the list") ;GUICtrlSetState(-1,$GUI_DISABLE) ;GUICtrlSetColor($DelectButton,0xff0000) $ProgLabel = GUICtrlCreateLabel("Accessing Database...", 600, 255, 150, 50) $Progress_1 = GUICtrlCreateProgress(750, 250, 220, 20, 0x0008) ; 0x0008 = $PBS_MARQUEE From <ProgressConstants.au3> _ProgressSetTheme() _ProgressSetMarquee($Progress_1, $Form1) $cClick_TV = GUICtrlCreateDummy() $cClick_LV = GUICtrlCreateDummy() GUISetState(@SW_SHOW) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $ItemApp GUICtrlSetState($AddButton, $GUI_SHOW) $App = True $Reg = False $Cust = False _GUICtrlTreeView_DeleteAll($hTreeView) _GUICtrlListView_DeleteAllItems($hListView) list() Case $ItemReg GUICtrlSetState($AddButton, $GUI_SHOW) $App = False $Reg = True $Cust = False _GUICtrlTreeView_DeleteAll($hTreeView) _GUICtrlListView_DeleteAllItems($hListView) Reg() Case $ItemCust GUICtrlSetState($AddButton, $GUI_SHOW) $App = False $Reg = False $Cust = True _GUICtrlTreeView_DeleteAll($hTreeView) _GUICtrlListView_DeleteAllItems($hListView) Cust() Case $AddButton ADDButton() Case $DelectButton DeleteButton() Case $EditButton ; $iEditMode = Number(GUICtrlRead($cCombo_Row) & GUICtrlRead($cCombo_Col)) Edit() Case $CancelButton cancelbutton() Case $cClick_TV ; Set mouse coord mode to active window client area $iOldOpt = Opt("MouseCoordMode", 2) Local $aMpos = MouseGetPos() ; Adjust for position of TreeView within client area Local $hItem = _GUICtrlTreeView_HitTestItem($hTreeView, $aMpos[0] - 20, $aMpos[1] - 30) ; Reset mous coord mode Opt("MouseCoordMode", $iOldOpt) Local $sText = _GUICtrlTreeView_GetText($hTreeView, $hItem) Local $fChecked = False If _GUICtrlTreeView_GetSelected($hTreeView, $hItem) Then $fChecked = True _TvCheckbox($sText, $fChecked) Case $cClick_LV ; MsgBox(0, "Hi", "ListView clicked") EndSwitch WEnd Func list() listcreate() For $i = 1 To 10 GUICtrlCreateTreeViewItem($i, $hTreeView) Next EndFunc ;==>list Func Reg() listcreate() For $i = 100 To 110 GUICtrlCreateTreeViewItem($i, $hTreeView) Next EndFunc ;==>Reg Func Cust() listcreate() For $i = 200 To 210 GUICtrlCreateTreeViewItem($i, $hTreeView) Next EndFunc ;==>Cust Func ADDButton() $TreeCount = _GUICtrlTreeView_GetCount($hTreeView) Do $AddInput = InputBox("BVAdmin", "Enter the Application Name") Until $AddInput <> "" GUICtrlCreateTreeViewItem($AddInput, $hTreeView) EndFunc ;==>ADDButton Func DeleteButton() _GUICtrlTreeView_Delete($hTreeView, $hItem) _GUICtrlListView_DeleteItem($hListView, 0) EndFunc ;==>DeleteButton Func Edit() $aLV_List_Right = _GUIListViewEx_ReadToArray($hListView, 0) $iLV_Left_Index = _GUIListViewEx_Init($aLV_List_Right, $aLV_List_Right, 0, 0, True, 1 + 2 + 8, "0;2") $aRet = _GUIListViewEx_EditItem($iLV_Left_Index, 0, 0, $iEditMode) EndFunc ;==>Edit Func listcreate() _GUICtrlListView_Destroy($hListView) If $App = True Then $hListView = GUICtrlCreateListView("Name|Location|Appversion|RegionID|App Type", 260, 30, 720, 80, $LVS_EDITLABELS) _GUICtrlListView_SetColumnWidth($hListView, 0, 200) _GUICtrlListView_SetColumnWidth($hListView, 1, 220) _GUICtrlListView_SetColumnWidth($hListView, 2, 100) _GUICtrlListView_SetColumnWidth($hListView, 3, 70) _GUICtrlListView_SetColumnWidth($hListView, 4, $LVSCW_AUTOSIZE_USEHEADER) ElseIf $Reg = True Then $hListView = GUICtrlCreateListView("Name|Location|Keypath|Value|Mode", 260, 30, 720, 80, $LVS_EDITLABELS) _GUICtrlListView_SetColumnWidth($hListView, 0, 200) _GUICtrlListView_SetColumnWidth($hListView, 1, 220) _GUICtrlListView_SetColumnWidth($hListView, 2, 200) _GUICtrlListView_SetColumnWidth($hListView, 3, 50) _GUICtrlListView_SetColumnWidth($hListView, 4, $LVSCW_AUTOSIZE_USEHEADER) ElseIf $Cust = True Then $hListView = GUICtrlCreateListView("Name|Location", 260, 30, 720, 80, $LVS_EDITLABELS) _GUICtrlListView_SetColumnWidth($hListView, 0, 200) _GUICtrlListView_SetColumnWidth($hListView, 1, $LVSCW_AUTOSIZE_USEHEADER) EndIf EndFunc ;==>listcreate Func _TvCheckbox($hItem, $fChecked) If $App = True Then If $fChecked = True Then GUICtrlSetState($EditButton, $GUI_SHOW) GUICtrlSetState($CancelButton, $GUI_SHOW) GUICtrlSetState($DelectButton, $GUI_SHOW) _GUICtrlListView_DeleteAllItems($hListView) $hListViewItem = GUICtrlCreateListViewItem($hItem & "|" & $hItem & "|" & $hItem & "|" & $hItem & "|" & $hItem, $hListView) EndIf ElseIf $Reg = True Then GUICtrlSetState($EditButton, $GUI_SHOW) GUICtrlSetState($CancelButton, $GUI_SHOW) GUICtrlSetState($DelectButton, $GUI_SHOW) _GUICtrlListView_DeleteAllItems($hListView) $hListViewItem = GUICtrlCreateListViewItem($hItem & "|" & $hItem & "|" & $hItem & "|" & $hItem & "|" & $hItem, $hListView) ElseIf $Cust = True Then GUICtrlSetState($EditButton, $GUI_SHOW) GUICtrlSetState($CancelButton, $GUI_SHOW) GUICtrlSetState($DelectButton, $GUI_SHOW) _GUICtrlListView_DeleteAllItems($hListView) $hListViewItem = GUICtrlCreateListViewItem($hItem & "|" & $hItem, $hListView) EndIf EndFunc ;==>_TvCheckbox Func WM_NOTIFY($hWnd, $msg, $wParam, $lParam) Local $tNMHDR, $IdFrom, $iCode $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $IdFrom = DllStructGetData($tNMHDR, "IdFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $iCode Case $NM_CLICK ConsoleWrite($IdFrom & @CRLF) Switch $IdFrom Case $hTreeView GUICtrlSendToDummy($cClick_TV) Case $hListView GUICtrlSendToDummy($cClick_LV) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func FrameRect($hDC, $nLeft, $nTop, $nRight, $nBottom, $hBrush) Local $stRect = DllStructCreate("int;int;int;int") DllStructSetData($stRect, 1, $nLeft) DllStructSetData($stRect, 2, $nTop) DllStructSetData($stRect, 3, $nRight) DllStructSetData($stRect, 4, $nBottom) DllCall("user32.dll", "int", "FrameRect", "hwnd", $hDC, "ptr", DllStructGetPtr($stRect), "hwnd", $hBrush) EndFunc ;==>FrameRect Func cancelbutton() EndFunc Thanks in advance! Edited December 10, 2013 by Syed23 Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]
Moderators Melba23 Posted December 10, 2013 Moderators Posted December 10, 2013 Syed23,This shows you how to integrate the UDF into your script - although there is still a lot for you to do to complete it as I have only made it work for the "Apps" part: expandcollapse popup#include <GUIConstants.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> #include <GuiTreeView.au3> #include <TreeViewConstants.au3> #include <GuiListView.au3> #include <ListviewConstants.au3> #include <GuiComboBox.au3> #include <Misc.au3> #include <GuiListBox.au3> #include <EditConstants.au3> #include <GuiEdit.au3> #include <UpdownConstants.au3> #include <ButtonConstants.au3> #include "GUIListViewEx.au3" Global $iWidth = 210, $iHeight = 20, $iLeft = 10, $iTop = 10 ; <<<<< Change Values here. Global $hTreeView, $hListView, $hItem, $hBrush, $Progress, $hListViewItem, $iCount = 0, $hEdit, $Item, $iText, $SubItem, $hDC, $iEditMode = 0 Global $Style = BitOR($WS_CHILD, $WS_VISIBLE, $ES_AUTOHSCROLL, $ES_LEFT) Global $iLV_Index $Form1 = GUICreate("BVAdmin", 1000, 343, -1, -1) GUISetBkColor(0xFFFFFF) $Menu1 = GUICtrlCreateMenu("Load") $Menu2 = GUICtrlCreateMenu("Save") $ItemApp = GUICtrlCreateMenuItem("Application", $Menu1) $ItemReg = GUICtrlCreateMenuItem("Reg Files", $Menu1) $ItemCust = GUICtrlCreateMenuItem("Custom Files", $Menu1) $ItemSave = GUICtrlCreateMenuItem("Save", $Menu2) $Itemexit = GUICtrlCreateMenuItem("Exit", $Menu2) $Group = GUICtrlCreateGroup("List", 5, 10, 210, 300) $hTreeView = GUICtrlCreateTreeView(20, 30, 180, 270) $Group1 = GUICtrlCreateGroup("Data", 240, 10, 750, 180) $AddButton = GUICtrlCreateButton("Add", 270, 160, 40, 30) GUICtrlSetState(-1, $GUI_HIDE) $EditButton = GUICtrlCreateButton("Edit", 320, 160, 40, 30) GUICtrlSetState(-1, $GUI_HIDE) $CancelButton = GUICtrlCreateButton("Delete", 370, 160, 40, 30) GUICtrlSetState(-1, $GUI_HIDE) $DelectButton = GUICtrlCreateButton("X", 420, 160, 40, 30) GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0xFF0000) GUICtrlSetState(-1, $GUI_HIDE) $ProgLabel = GUICtrlCreateLabel("Accessing Database...", 600, 255, 150, 50) $Progress_1 = GUICtrlCreateProgress(750, 250, 220, 20, 0x0008) $cClick_TV = GUICtrlCreateDummy() $cClick_LV = GUICtrlCreateDummy() GUISetState(@SW_SHOW) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") _GUIListViewEx_MsgRegister(False, True, True) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $ItemApp GUICtrlSetState($AddButton, $GUI_SHOW) $App = True $Reg = False $Cust = False _GUICtrlTreeView_DeleteAll($hTreeView) _GUICtrlListView_DeleteAllItems($hListView) list() Case $ItemReg GUICtrlSetState($AddButton, $GUI_SHOW) $App = False $Reg = True $Cust = False _GUICtrlTreeView_DeleteAll($hTreeView) _GUICtrlListView_DeleteAllItems($hListView) Reg() Case $ItemCust GUICtrlSetState($AddButton, $GUI_SHOW) $App = False $Reg = False $Cust = True _GUICtrlTreeView_DeleteAll($hTreeView) _GUICtrlListView_DeleteAllItems($hListView) Cust() Case $AddButton ADDButton() Case $DelectButton DeleteButton() Case $EditButton ; $iEditMode = Number(GUICtrlRead($cCombo_Row) & GUICtrlRead($cCombo_Col)) Edit() Case $CancelButton cancelbutton() Case $cClick_TV ; Set mouse coord mode to active window client area $iOldOpt = Opt("MouseCoordMode", 2) Local $aMpos = MouseGetPos() ; Adjust for position of TreeView within client area Local $hItem = _GUICtrlTreeView_HitTestItem($hTreeView, $aMpos[0] - 20, $aMpos[1] - 30) ; Reset mous coord mode Opt("MouseCoordMode", $iOldOpt) Local $sText = _GUICtrlTreeView_GetText($hTreeView, $hItem) Local $fChecked = False If _GUICtrlTreeView_GetSelected($hTreeView, $hItem) Then $fChecked = True _TvCheckbox($sText, $fChecked) Case $cClick_LV ; MsgBox(0, "Hi", "ListView clicked") EndSwitch ; Run on click _GUIListViewEx_EditOnClick() WEnd Func list() listcreate() For $i = 1 To 10 GUICtrlCreateTreeViewItem("Item " & $i, $hTreeView) Next EndFunc ;==>list Func Reg() listcreate() For $i = 100 To 110 GUICtrlCreateTreeViewItem("Item " & $i, $hTreeView) Next EndFunc ;==>Reg Func Cust() listcreate() For $i = 200 To 210 GUICtrlCreateTreeViewItem("Item " & $i, $hTreeView) Next EndFunc ;==>Cust Func ADDButton() $TreeCount = _GUICtrlTreeView_GetCount($hTreeView) Do $AddInput = InputBox("BVAdmin", "Enter the Application Name") Until $AddInput <> "" GUICtrlCreateTreeViewItem($AddInput, $hTreeView) EndFunc ;==>ADDButton Func DeleteButton() _GUICtrlTreeView_Delete($hTreeView, $hItem) _GUICtrlListView_DeleteItem($hListView, 0) EndFunc ;==>DeleteButton Func Edit() EndFunc ;==>Edit Func listcreate() ; Here you will need to save the changes by accessing the array like this $aArray = _GUIListViewEx_ReturnArray($iLV_Index) ; Close LV tracking _GUIListViewEx_Close($iLV_Index) _GUICtrlListView_Destroy($hListView) If $App = True Then $hListView = GUICtrlCreateListView("Name|Location|Appversion|RegionID|App Type", 260, 30, 720, 80, $LVS_EDITLABELS) _GUICtrlListView_SetColumnWidth($hListView, 0, 200) _GUICtrlListView_SetColumnWidth($hListView, 1, 220) _GUICtrlListView_SetColumnWidth($hListView, 2, 100) _GUICtrlListView_SetColumnWidth($hListView, 3, 70) _GUICtrlListView_SetColumnWidth($hListView, 4, $LVSCW_AUTOSIZE_USEHEADER) ElseIf $Reg = True Then $hListView = GUICtrlCreateListView("Name|Location|Keypath|Value|Mode", 260, 30, 720, 80, $LVS_EDITLABELS) _GUICtrlListView_SetColumnWidth($hListView, 0, 200) _GUICtrlListView_SetColumnWidth($hListView, 1, 220) _GUICtrlListView_SetColumnWidth($hListView, 2, 200) _GUICtrlListView_SetColumnWidth($hListView, 3, 50) _GUICtrlListView_SetColumnWidth($hListView, 4, $LVSCW_AUTOSIZE_USEHEADER) ElseIf $Cust = True Then $hListView = GUICtrlCreateListView("Name|Location", 260, 30, 720, 80, $LVS_EDITLABELS) _GUICtrlListView_SetColumnWidth($hListView, 0, 200) _GUICtrlListView_SetColumnWidth($hListView, 1, $LVSCW_AUTOSIZE_USEHEADER) EndIf ; Start LV tracking and edit $aLV_Arrray = _GUIListViewEx_ReadToArray($hListView, 0) $iLV_Index = _GUIListViewEx_Init($hListView, $aLV_Arrray, 0, 0, True, 1 + 2) EndFunc ;==>listcreate Func _TvCheckbox($hItem, $fChecked) If $App = True Then If $fChecked = True Then GUICtrlSetState($EditButton, $GUI_SHOW) GUICtrlSetState($CancelButton, $GUI_SHOW) GUICtrlSetState($DelectButton, $GUI_SHOW) ;_GUICtrlListView_DeleteAllItems($hListView) ;$hListViewItem = GUICtrlCreateListViewItem($hItem & "|" & $hItem & "|" & $hItem & "|" & $hItem & "|" & $hItem, $hListView) _GUIListViewEx_Insert($hItem & "|" & $hItem & "|" & $hItem & "|" & $hItem & "|" & $hItem) EndIf ElseIf $Reg = True Then GUICtrlSetState($EditButton, $GUI_SHOW) GUICtrlSetState($CancelButton, $GUI_SHOW) GUICtrlSetState($DelectButton, $GUI_SHOW) ;_GUICtrlListView_DeleteAllItems($hListView) $hListViewItem = GUICtrlCreateListViewItem($hItem & "|" & $hItem & "|" & $hItem & "|" & $hItem & "|" & $hItem, $hListView) ElseIf $Cust = True Then GUICtrlSetState($EditButton, $GUI_SHOW) GUICtrlSetState($CancelButton, $GUI_SHOW) GUICtrlSetState($DelectButton, $GUI_SHOW) ;_GUICtrlListView_DeleteAllItems($hListView) $hListViewItem = GUICtrlCreateListViewItem($hItem & "|" & $hItem, $hListView) EndIf EndFunc ;==>_TvCheckbox Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) Local $tNMHDR, $IdFrom, $iCode $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $IdFrom = DllStructGetData($tNMHDR, "IdFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $iCode Case $NM_CLICK Switch $IdFrom Case $hTreeView GUICtrlSendToDummy($cClick_TV) Case $hListView GUICtrlSendToDummy($cClick_LV) EndSwitch EndSwitch _GUIListViewEx_WM_NOTIFY_Handler($hWnd, $iMsg, $wParam, $lParam) Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func FrameRect($hDC, $nLeft, $nTop, $nRight, $nBottom, $hBrush) Local $stRect = DllStructCreate("int;int;int;int") DllStructSetData($stRect, 1, $nLeft) DllStructSetData($stRect, 2, $nTop) DllStructSetData($stRect, 3, $nRight) DllStructSetData($stRect, 4, $nBottom) DllCall("user32.dll", "int", "FrameRect", "hwnd", $hDC, "ptr", DllStructGetPtr($stRect), "hwnd", $hBrush) EndFunc ;==>FrameRect Func cancelbutton() EndFunc ;==>cancelbuttonI removed a lot of extraneous lines to clarify the working parts. Note how you need to intialise the ListView when you create it and then use the UDF to add items to it. Please ask if you have further questions - as I am sure will be the case! M23 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
Syed23 Posted December 10, 2013 Author Posted December 10, 2013 That was so quick! Thanks M23. I modified the code a bit with your example and it worked the way i wanted Thank you so much.. Here is the code which i modified.. expandcollapse popup#include <GUIConstants.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> #include <GuiTreeView.au3> #include <TreeViewConstants.au3> #include <GuiListView.au3> #include <ListviewConstants.au3> #include <GuiComboBox.au3> #include <Misc.au3> #include <GuiListBox.au3> #include <EditConstants.au3> #include <GuiEdit.au3> #include <UpdownConstants.au3> #include <ButtonConstants.au3> #include <_ProgressSetMarquee.au3> #include "GUIListViewEx.au3" #include <GuiButton.au3> Global $hDLL = DllOpen("user32.dll") FileInstall("C:\Users\Q03200\Desktop\ICONS\Semlabs-Web-Blog-Add.ico", @TempDir & "\Semlabs-Web-Blog-Add.ico", 1) FileInstall("C:\Users\Q03200\Desktop\ICONS\Creative-Freedom-Free-Funktional-05-Edit.ico", @TempDir & "\Creative-Freedom-Free-Funktional-05-Edit.ico", 1) FileInstall("C:\Users\Q03200\Desktop\ICONS\Fatcow-Farm-Fresh-Bullet-delete.ico", @TempDir & "\Fatcow-Farm-Fresh-Bullet-delete.ico", 1) Global $cancel = False, $i Global $iWidth = 210, $iHeight = 20, $iLeft = 10, $iTop = 10 ; <<<<< Change Values here. Global $hTreeView, $hListView, $hItem, $hBrush, $Progress, $hListViewItem, $iCount = 0,$hEdit,$Item,$iText,$SubItem,$hDC,$iEditMode = 0 Global $Style = BitOR($WS_CHILD, $WS_VISIBLE, $ES_AUTOHSCROLL, $ES_LEFT) $Form1 = GUICreate("BVAdmin", 1000, 343, -1, -1) GUISetBkColor(0xFFFFFF) $Menu1 = GUICtrlCreateMenu("Load") $Menu2 = GUICtrlCreateMenu("Save") $ItemApp = GUICtrlCreateMenuItem("Application", $Menu1) $ItemReg = GUICtrlCreateMenuItem("Reg Files", $Menu1) $ItemCust = GUICtrlCreateMenuItem("Custom Files", $Menu1) $ItemSave = GUICtrlCreateMenuItem("Save", $Menu2) $Itemexit = GUICtrlCreateMenuItem("Exit", $Menu2) $Group = GUICtrlCreateGroup("List", 5, 10, 210, 300) $hTreeView = GUICtrlCreateTreeView(20, 30, 180, 270) $Group1 = GUICtrlCreateGroup("Data", 240, 10, 750, 180) $AddButton = GUICtrlCreateButton("", 270, 160, 40, 30, $BS_ICON) GUICtrlSetImage(-1, @TempDir & "\Semlabs-Web-Blog-Add.ico", -1, 0) GUICtrlSetState(-1, $GUI_HIDE) GUICtrlSetTip(-1, "Allows you to Add new Entry to the list") ;GUICtrlSetColor($AddButton,0x0B610B) $EditButton = GUICtrlCreateButton("", 320, 160, 40, 30, $BS_ICON) ;GUICtrlSetState(-1,$GUI_DISABLE) ;GUICtrlSetColor($EditButton,0x0000FF) GUICtrlSetImage($EditButton, @TempDir & "\Creative-Freedom-Free-Funktional-05-Edit.ico", -1, 0) GUICtrlSetState(-1, $GUI_HIDE) GUICtrlSetTip(-1, "Allows you to Edit ListBox") $CancelButton = GUICtrlCreateButton("", 370, 160, 40, 30, $BS_ICON) GUICtrlSetImage($CancelButton, @TempDir & "\Fatcow-Farm-Fresh-Bullet-delete.ico", -1, 0) GUICtrlSetState(-1, $GUI_HIDE) GUICtrlSetTip(-1, "Allows you to Cancel the Editing mode") ;GUICtrlSetState(-1,$GUI_DISABLE) ;GUICtrlSetColor($CancelButton,0xff0000) $DelectButton = GUICtrlCreateButton("X", 420, 160, 40, 30) GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0xFF0000) GUICtrlSetState(-1, $GUI_HIDE) GUICtrlSetTip(-1, "Allows you to Delete the Entry from the list") ;GUICtrlSetState(-1,$GUI_DISABLE) ;GUICtrlSetColor($DelectButton,0xff0000) $ProgLabel = GUICtrlCreateLabel("Accessing Database...", 600, 255, 150, 50) $Progress_1 = GUICtrlCreateProgress(750, 250, 220, 20, 0x0008) ; 0x0008 = $PBS_MARQUEE From <ProgressConstants.au3> _ProgressSetTheme() _ProgressSetMarquee($Progress_1, $Form1) $cClick_TV = GUICtrlCreateDummy() $cClick_LV = GUICtrlCreateDummy() GUISetState(@SW_SHOW) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $ItemApp GUICtrlSetState($AddButton, $GUI_SHOW) $App = True $Reg = False $Cust = False _GUICtrlTreeView_DeleteAll($hTreeView) _GUICtrlListView_DeleteAllItems($hListView) list() Case $ItemReg GUICtrlSetState($AddButton, $GUI_SHOW) $App = False $Reg = True $Cust = False _GUICtrlTreeView_DeleteAll($hTreeView) _GUICtrlListView_DeleteAllItems($hListView) Reg() Case $ItemCust GUICtrlSetState($AddButton, $GUI_SHOW) $App = False $Reg = False $Cust = True _GUICtrlTreeView_DeleteAll($hTreeView) _GUICtrlListView_DeleteAllItems($hListView) Cust() Case $AddButton ADDButton() Case $DelectButton DeleteButton() Case $EditButton ; $iEditMode = Number(GUICtrlRead($cCombo_Row) & GUICtrlRead($cCombo_Col)) Edit() ; Case $CancelButton ; MsgBox(0,"",_GUICtrlButton_GetState($CancelButton)) ;MsgBox(0,"",$HeaderCount) Case $cClick_TV ; Set mouse coord mode to active window client area $iOldOpt = Opt("MouseCoordMode", 2) Local $aMpos = MouseGetPos() ; Adjust for position of TreeView within client area Local $hItem = _GUICtrlTreeView_HitTestItem($hTreeView, $aMpos[0] - 20, $aMpos[1] - 30) ; Reset mous coord mode Opt("MouseCoordMode", $iOldOpt) Local $sText = _GUICtrlTreeView_GetText($hTreeView, $hItem) Local $fChecked = False If _GUICtrlTreeView_GetSelected($hTreeView, $hItem) Then $fChecked = True _TvCheckbox($sText, $fChecked) Case $cClick_LV ; MsgBox(0, "Hi", "ListView clicked") EndSwitch WEnd Func list() listcreate() For $i = 1 To 10 GUICtrlCreateTreeViewItem($i, $hTreeView) Next EndFunc ;==>list Func Reg() listcreate() For $i = 100 To 110 GUICtrlCreateTreeViewItem($i, $hTreeView) Next EndFunc ;==>Reg Func Cust() listcreate() For $i = 200 To 210 GUICtrlCreateTreeViewItem($i, $hTreeView) Next EndFunc ;==>Cust Func ADDButton() $TreeCount = _GUICtrlTreeView_GetCount($hTreeView) Do $AddInput = InputBox("BVAdmin", "Enter the Application Name") Until $AddInput <> "" GUICtrlCreateTreeViewItem($AddInput, $hTreeView) EndFunc ;==>ADDButton Func DeleteButton() _GUICtrlTreeView_Delete($hTreeView, $hItem) _GUICtrlListView_DeleteItem($hListView, 0) EndFunc ;==>DeleteButton Func Edit() $aLV_List_Right = _GUIListViewEx_ReadToArray($hListView, 0) $iLV_Left_Index = _GUIListViewEx_Init($hListView, $aLV_List_Right, 0, 0, True, 1 + 2 + 8, "0;2") Global $HeaderCount = _GUICtrlListView_GetColumnCount($hListView) For $i = 0 To $HeaderCount $aRet = _GUIListViewEx_EditItem($iLV_Left_Index, 0, $i, $iEditMode) Sleep("250") If _GUICtrlButton_GetState($CancelButton) = "520" Then $i= $HeaderCount +1 EndIf Next EndFunc ;==>Edit Func listcreate() _GUICtrlListView_Destroy($hListView) If $App = True Then $hListView = GUICtrlCreateListView("Name|Location|Appversion|RegionID|App Type", 260, 30, 720, 80, $LVS_EDITLABELS) _GUICtrlListView_SetColumnWidth($hListView, 0, 200) _GUICtrlListView_SetColumnWidth($hListView, 1, 220) _GUICtrlListView_SetColumnWidth($hListView, 2, 100) _GUICtrlListView_SetColumnWidth($hListView, 3, 70) _GUICtrlListView_SetColumnWidth($hListView, 4, $LVSCW_AUTOSIZE_USEHEADER) ElseIf $Reg = True Then $hListView = GUICtrlCreateListView("Name|Location|Keypath|Value|Mode", 260, 30, 720, 80, $LVS_EDITLABELS) _GUICtrlListView_SetColumnWidth($hListView, 0, 200) _GUICtrlListView_SetColumnWidth($hListView, 1, 220) _GUICtrlListView_SetColumnWidth($hListView, 2, 200) _GUICtrlListView_SetColumnWidth($hListView, 3, 50) _GUICtrlListView_SetColumnWidth($hListView, 4, $LVSCW_AUTOSIZE_USEHEADER) ElseIf $Cust = True Then $hListView = GUICtrlCreateListView("Name|Location", 260, 30, 720, 80, $LVS_EDITLABELS) _GUICtrlListView_SetColumnWidth($hListView, 0, 200) _GUICtrlListView_SetColumnWidth($hListView, 1, $LVSCW_AUTOSIZE_USEHEADER) EndIf EndFunc ;==>listcreate Func _TvCheckbox($hItem, $fChecked) If $App = True Then If $fChecked = True Then GUICtrlSetState($EditButton, $GUI_SHOW) GUICtrlSetState($CancelButton, $GUI_SHOW) GUICtrlSetState($DelectButton, $GUI_SHOW) _GUICtrlListView_DeleteAllItems($hListView) $hListViewItem = GUICtrlCreateListViewItem($hItem & "|" & $hItem & "|" & $hItem & "|" & $hItem & "|" & $hItem, $hListView) EndIf ElseIf $Reg = True Then GUICtrlSetState($EditButton, $GUI_SHOW) GUICtrlSetState($CancelButton, $GUI_SHOW) GUICtrlSetState($DelectButton, $GUI_SHOW) _GUICtrlListView_DeleteAllItems($hListView) $hListViewItem = GUICtrlCreateListViewItem($hItem & "|" & $hItem & "|" & $hItem & "|" & $hItem & "|" & $hItem, $hListView) ElseIf $Cust = True Then GUICtrlSetState($EditButton, $GUI_SHOW) GUICtrlSetState($CancelButton, $GUI_SHOW) GUICtrlSetState($DelectButton, $GUI_SHOW) _GUICtrlListView_DeleteAllItems($hListView) $hListViewItem = GUICtrlCreateListViewItem($hItem & "|" & $hItem, $hListView) EndIf EndFunc ;==>_TvCheckbox Func WM_NOTIFY($hWnd, $msg, $wParam, $lParam) Local $tNMHDR, $IdFrom, $iCode $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $IdFrom = DllStructGetData($tNMHDR, "IdFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $iCode Case $NM_CLICK ConsoleWrite($IdFrom & @CRLF) Switch $IdFrom Case $hTreeView GUICtrlSendToDummy($cClick_TV) Case $hListView GUICtrlSendToDummy($cClick_LV) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func FrameRect($hDC, $nLeft, $nTop, $nRight, $nBottom, $hBrush) Local $stRect = DllStructCreate("int;int;int;int") DllStructSetData($stRect, 1, $nLeft) DllStructSetData($stRect, 2, $nTop) DllStructSetData($stRect, 3, $nRight) DllStructSetData($stRect, 4, $nBottom) DllCall("user32.dll", "int", "FrameRect", "hwnd", $hDC, "ptr", DllStructGetPtr($stRect), "hwnd", $hBrush) EndFunc ;==>FrameRect Func Cancel($temp) $i=$temp Return $i EndFunc Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]
Moderators Melba23 Posted December 10, 2013 Moderators Posted December 10, 2013 Syed23,Glad I could help. You know where I am if you need anything further. M23 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
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