gobsor Posted August 13, 2010 Share Posted August 13, 2010 Heya, I read a lot on ListView editing by mouse-clicks today, finally i figured out how to get the row-number/column-number of ListView Items/SubItems! Okay, I am now able to edit a ListView item using _GUICtrlListView_EDITLabel($hListView, $iIndex) which allows me to edit ListView item's by double-clicking them using a $WM_NOTIFY function. But how do I edit ListView SubItems? Since _GUICtrlListView_EDITLabel($hwnd, $index) only takes the $index, I am only able to go "down" through the first column of the ListView. I can edit all Items but not the SubItems of those. I couldn't find any function that allows me to, lets say _GUICtrlListView_EDITSubItemLabel($hwnd, $row, $column) or something similiar, any idea on how to procede? regards Link to comment Share on other sites More sharing options...
smashly Posted August 13, 2010 Share Posted August 13, 2010 Hi, You'll need to do a to find when a sub item is double clicked and then draw your own edit edit field and update the sub item when the user has finished. Here's a crude example of in place edit on 1st and Sub item edit of a listviewexpandcollapse popup#include <GuiListView.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <WinAPI.au3> Global $hGuui, $hListView Global $hEdit, $hDC, $hBrush, $Item = -1, $SubItem = 0 $hGUI = GUICreate("ListView Subitems edit in place", 300, 200) $hListView = _GUICtrlListView_Create($hGUI, "Items|SubItems", 2, 2, 296, 196, BitOR($LVS_EDITLABELS, $LVS_REPORT)) _GUICtrlListView_SetExtendedListViewStyle($hListView, $LVS_EX_GRIDLINES) For $i = 1 To 10 _GUICtrlListView_AddItem($hListView, "Item " & $i) _GUICtrlListView_AddSubItem($hListView, $i - 1, "SubItem " & $i, 1) Next GUISetState(@SW_SHOW, $hGuui) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") Do Until GUIGetMsg() = $GUI_EVENT_CLOSE Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Local $tNMHDR, $hWndFrom, $iCode $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hListView Switch $iCode Case $NM_DBLCLK ; used for sub item edit Local $aHit = _GUICtrlListView_SubItemHitTest($hListView) If ($aHit[0] <> -1) And ($aHit[1] > 0) Then $Item = $aHit[0] $SubItem = $aHit[1] Local $iSubItemText = _GUICtrlListView_GetItemText($hListView, $Item, $SubItem) Local $iLen = _GUICtrlListView_GetStringWidth($hListView, $iSubItemText) Local $aRect = _GUICtrlListView_GetSubItemRect($hListView, $Item, $SubItem) $hEdit = _GUICtrlEdit_Create($hGUI, $iSubItemText, $aRect[0] + 6, $aRect[1], $iLen + 10, 17, BitOR($WS_CHILD, $WS_VISIBLE, $ES_AUTOHSCROLL, $ES_LEFT)) _GUICtrlEdit_SetSel($hEdit, 0, -1) _WinAPI_SetFocus($hEdit) $hDC = _WinAPI_GetWindowDC($hEdit) $hBrush = _WinAPI_CreateSolidBrush(0) FrameRect($hDC, 0, 0, $iLen + 10, 17, $hBrush) EndIf Case $LVN_ENDLABELEDITA, $LVN_ENDLABELEDITW ; Used for 1st column edit Local $tInfo = DllStructCreate($tagNMLVDISPINFO, $ilParam) Local $tBuffer = DllStructCreate("char Text[" & DllStructGetData($tInfo, "TextMax") & "]", DllStructGetData($tInfo, "Text")) If StringLen(DllStructGetData($tBuffer, "Text")) Then Return True 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 Cheers Link to comment Share on other sites More sharing options...
gobsor Posted August 14, 2010 Author Share Posted August 14, 2010 Thanks a lot! Works like a charm! Link to comment Share on other sites More sharing options...
Saad Posted December 14, 2021 Share Posted December 14, 2021 I know it is an old thread. Hopefully someone will help with answering my quesion. How can I handle hitting the enter key, to end editing, while editing a cell in the middle of a row? Thanks. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 14, 2021 Moderators Share Posted December 14, 2021 Saad, Take a look at my GUIListViewEx UDF (the link is in my sig). 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 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