jresine Posted September 9, 2015 Share Posted September 9, 2015 (edited) Original code : https://www.autoitscript.com/forum/topic/75406-listview-subitems-edit-in-place-by-double-click/ Hello , I have a problem with this code , the edit control works perfectly, but the combo control does not work, someone would have an idea of where the problem come ?Thanks in advance.expandcollapse popup#include <GuiConstantsEx.au3> #include <GuiListView.au3> #include <GuiEdit.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <WinAPI.au3> #include <GuiComboBoxEx.au3> Opt("GuiCloseOnESC", 0) Global $hEdit, $hCombo, $Item = -1, $SubItem = 0 Global $Style = BitOR($WS_CHILD, $WS_VISIBLE, $WS_BORDER, $ES_AUTOHSCROLL, $ES_LEFT) $hGUI = GUICreate("ListView Subitems edit in place", 300, 200) $hListView = _GUICtrlListView_Create($hGUI, "Items|EDIT|COMBO", 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 GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") GUISetState() 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 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 $aRect = _GUICtrlListView_GetSubItemRect($hListView, $Item, $SubItem) If $aHit[1] == 1 Then $hEdit = _GUICtrlEdit_Create($hGUI, $iSubItemText, $aRect[0] + 1, $aRect[1] - 4, $aRect[2] - $aRect[0], 20, $Style) _WinAPI_SetFocus($hEdit) ElseIf $aHit[1] == 2 Then $hCombo = _GUICtrlComboBoxEx_Create($hGUI,$iSubItemText & "|test 1|texte 2| fin 3", $aRect[0] + 1, $aRect[1] - 4, $aRect[2] - $aRect[0], 20, $Style) _WinAPI_SetFocus($hCombo) EndIf EndIf EndSwitch EndSwitch EndFunc 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_DestroyWindow($hEdit) $Item = -1 $SubItem = 0 EndSwitch Case $hCombo Switch $iCode Case $EN_KILLFOCUS Local $iText = _GUICtrlComboBoxEx_GetEditText($hCombo) _GUICtrlListView_SetItemText($hListView, $Item, $iText, $SubItem) _WinAPI_DestroyWindow($hCombo) $Item = -1 $SubItem = 0 EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFuncJR. Edited September 9, 2015 by jresine Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 9, 2015 Moderators Share Posted September 9, 2015 jresine,I would suggest using my GUIListViewEx UDF instead - much easier to code:#include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include "GUIListViewEx.au3" Opt("GuiCloseOnESC", 0) $hGUI = GUICreate("ListView Subitems edit in place", 300, 200) $hListView = _GUICtrlListView_Create($hGUI, "Items|EDIT|COMBO", 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() ; Read ListView contents $aListViewContent = _GUIListViewEx_ReadToArray($hListView) ; Initialise ListView $iLV_Index = _GUIListViewEx_Init($hListView, $aListViewContent, 0, 0, True, 2 + 16, "1;2") ; Set combo data for the required column _GUIListViewEx_ComboData($iLV_Index, 2, "Choice 1|Choice 2|Choice 3") ; Register required messages _GUIListViewEx_MsgRegister() While 1 If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit ; Look for the edit doubleclicks _GUIListViewEx_EditOnClick() WEndYou can find the link 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...
jresine Posted September 10, 2015 Author Share Posted September 10, 2015 Hello and thank you for this function.But I can not find a function to change the text color or background.Is there also a function for text size ? JR. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 10, 2015 Moderators Share Posted September 10, 2015 jresine,You just use the normal AutoIt functions to change the basic ListView attributes - GUICtrlSetColor/BkColor/Font for native ListViews or the equivalent _GUICtrlListView_* functions for the UDF-created ones . As you create the control you can set it up as you wish, all the UDF does is look after the content.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...
jresine Posted September 10, 2015 Author Share Posted September 10, 2015 (edited) Hello , yes I know, but what I would like is a color per cell. I used this code in my script :_WinAPI_SetFont($list,_WinAPI_CreateFont(20,0),False)and this for cell background color :expandcollapse popupFunc WM_NOTIFY($hWnd,$iMsg,$iwParam,$ilParam) Local $tNMHDR,$hWndFrom,$iCode $tNMHDR = DllStructCreate("struct;hwnd hWndFrom;uint_ptr IDFrom;INT Code;endstruct",$ilParam) $hWndFrom = DllStructGetData($tNMHDR,"hWndFrom") $iCode = DllStructGetData($tNMHDR,"Code") Switch $hWndFrom Case $list Switch $iCode Case -12 Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW,$ilParam) Local $iDrawStage = DllStructGetData($tCustDraw,"dwDrawStage") Switch $iDrawStage Case 0x00000001 Return 0x00000020 Case 0x00010001 Return 0x00000020 EndSwitch Local $iItem = DllStructGetData($tCustDraw,"dwItemSpec") Local $iSubItem = DllStructGetData($tCustDraw,"iSubItem") Local $hDC = DllStructGetData($tCustDraw,'hdc') ;f7f7f7 If $iSubItem == 0 Then If _GUICtrlListView_GetItemText($list,$iItem,0) == "" Then DllStructSetData($tCustDraw,"clrTextBk",0xf7f7f7) EndIf EndIf If $iSubItem == 7 Then If _GUICtrlListView_GetItemText($list,$iItem,7) <> 0 Then DllStructSetData($tCustDraw,"clrTextBk",0x0000FF) EndIf EndIf If $iSubItem == 8 Then If _GUICtrlListView_GetItemText($list,$iItem,0) == "" Then DllStructSetData($tCustDraw,"clrTextBk",0xf7f7f7) Else DllStructSetData($tCustDraw,"clrTextBk",0xffffff) EndIf EndIf Return 0x00000002 ........ Edited September 10, 2015 by jresine Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 10, 2015 Moderators Share Posted September 10, 2015 jresine,This thread popped up when I searched for "ListView colour". You did try that before posting I suppose?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...
jresine Posted September 10, 2015 Author Share Posted September 10, 2015 Yes, I have tested. But the colors "bug" without refresh the window.Also the functions listview edit and combo is broken :/ expandcollapse popup#include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include<GuiListView.au3> #include "GUIListViewEx.au3" #include<WinAPI.au3> Opt("GuiCloseOnESC", 0) $hGUI = GUICreate("ListView Subitems edit in place", 300, 300) $hListView = _GUICtrlListView_Create($hGUI, "Items|EDIT|COMBO", 0, 0, 300, 300,$LVS_REPORT) _GUICtrlListView_SetExtendedListViewStyle($hListView, $LVS_EX_GRIDLINES) _WinAPI_SetFont($hListView,_WinAPI_CreateFont(20,0),False) For $i = 1 To 10 _GUICtrlListView_AddItem($hListView, "Item " & $i) _GUICtrlListView_AddSubItem($hListView, $i - 1, "SubItem " & $i, 1) Next GUISetState() $aListViewContent = _GUIListViewEx_ReadToArray($hListView) $iLV_Index = _GUIListViewEx_Init($hListView, $aListViewContent, 0, 0, True, 2 + 16, "*") _GUIListViewEx_ComboData($iLV_Index, 2, "Choice 1|Choice 2|Choice 3",True) _GUIListViewEx_MsgRegister() GUIRegisterMsg(0x004E,"WM_NOTIFY") While 1 If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit ; Look for the edit doubleclicks _GUIListViewEx_EditOnClick() WEnd Func WM_NOTIFY($hWnd,$iMsg,$iwParam,$ilParam) Local $tNMHDR,$hWndFrom,$iCode $tNMHDR = DllStructCreate("struct;hwnd hWndFrom;uint_ptr IDFrom;INT Code;endstruct",$ilParam) $hWndFrom = DllStructGetData($tNMHDR,"hWndFrom") $iCode = DllStructGetData($tNMHDR,"Code") Switch $hWndFrom Case $hListView Switch $iCode Case -12 Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW,$ilParam) Local $iDrawStage = DllStructGetData($tCustDraw,"dwDrawStage") Switch $iDrawStage Case 0x00000001 Return 0x00000020 Case 0x00010001 Return 0x00000020 EndSwitch Local $iItem = DllStructGetData($tCustDraw,"dwItemSpec") Local $iSubItem = DllStructGetData($tCustDraw,"iSubItem") Local $hDC = DllStructGetData($tCustDraw,'hdc') ;f7f7f7 If $iSubItem == 0 Then DllStructSetData($tCustDraw,"clrTextBk",0xf7f7f7) EndIf If $iSubItem == 1 Then DllStructSetData($tCustDraw,"clrTextBk",0x0000FF) EndIf If $iSubItem == 2 Then DllStructSetData($tCustDraw,"clrTextBk",0xffffff) EndIf Return 0x00000002 EndSwitch EndSwitch EndFuncJR. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 10, 2015 Moderators Share Posted September 10, 2015 jresine,Also the functions listview edit and combo is broken :/As explained in the UDF headers, you do not use the _GUIListViewEx_MsgRegister function if you already have the relevant message handlers - you need to add the UDF handler function(s) inside the existing handler(s).But the colors "bug" without refresh the windowPerhaps post in that thread to see if there is a fix?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...
jresine Posted September 11, 2015 Author Share Posted September 11, 2015 Good morning !OK, it work. But the listview does not turn while "gray" in the edition . Can we repair or disable it ?expandcollapse popup#include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include<GuiListView.au3> #include "GUIListViewEx.au3" #include<WinAPI.au3> Opt("GuiCloseOnESC", 0) $hGUI = GUICreate("ListView Subitems edit in place", 300, 300) $hListView = _GUICtrlListView_Create($hGUI, "Items|EDIT|COMBO", 0, 0, 300, 300,$LVS_REPORT) _GUICtrlListView_SetExtendedListViewStyle($hListView, $LVS_EX_GRIDLINES) _WinAPI_SetFont($hListView,_WinAPI_CreateFont(20,0),False) For $i = 1 To 10 _GUICtrlListView_AddItem($hListView, "Item " & $i) _GUICtrlListView_AddSubItem($hListView, $i - 1, "SubItem " & $i, 1) Next $aListViewContent = _GUIListViewEx_ReadToArray($hListView) $iLV_Index = _GUIListViewEx_Init($hListView, $aListViewContent, 0, 0, True, 2 + 16, "*") _GUIListViewEx_ComboData($iLV_Index, 2, "Choice 1|Choice 2|Choice 3",True) GUIRegisterMsg(0x004E,"WM_NOTIFY") GUIRegisterMsg(0x0200, "_GUIListViewEx_WM_MOUSEMOVE_Handler") GUIRegisterMsg(0x0202, "_GUIListViewEx_WM_LBUTTONUP_Handler") GUISetState() While 1 If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit _GUIListViewEx_EditOnClick() WEnd Func WM_NOTIFY($hWnd,$iMsg,$iwParam,$ilParam) _GUIListViewEx_WM_NOTIFY_Handler($hWnd, $iMsg, $iwParam, $ilParam) Local $tNMHDR,$hWndFrom,$iCode $tNMHDR = DllStructCreate("struct;hwnd hWndFrom;uint_ptr IDFrom;INT Code;endstruct",$ilParam) $hWndFrom = DllStructGetData($tNMHDR,"hWndFrom") $iCode = DllStructGetData($tNMHDR,"Code") Switch $hWndFrom Case $hListView Switch $iCode Case -12 Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW,$ilParam) Local $iDrawStage = DllStructGetData($tCustDraw,"dwDrawStage") Switch $iDrawStage Case 0x00000001 Return 0x00000020 Case 0x00010001 Return 0x00000020 EndSwitch Local $iItem = DllStructGetData($tCustDraw,"dwItemSpec") Local $iSubItem = DllStructGetData($tCustDraw,"iSubItem") Local $hDC = DllStructGetData($tCustDraw,'hdc') ;f7f7f7 If $iSubItem == 0 Then DllStructSetData($tCustDraw,"clrTextBk",0xf7f7f7) EndIf If $iSubItem == 1 Then DllStructSetData($tCustDraw,"clrTextBk",0x0000FF) EndIf If $iSubItem == 2 Then DllStructSetData($tCustDraw,"clrTextBk",0xffffff) EndIf Return 0x00000002 EndSwitch EndSwitch EndFunc Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 11, 2015 Moderators Share Posted September 11, 2015 jresine,I am stuck in Madrid airport at the moment (such fun!) - I will look into the problem over the weekend.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...
Moderators Melba23 Posted September 12, 2015 Moderators Share Posted September 12, 2015 jresine,Back home again after the delay.But the listview does not turn while "gray" in the editionI am unsure what you mean - can you please expand a bit.And you slightly misunderstood the registering - you can still use the _GUIListViewEx_MsgRegister function for the other messages - like this:GUIRegisterMsg($WM_NOTIFY,"WM_NOTIFY") _GUIListViewEx_MsgRegister(False)Now the WM_MOUSEMOVE & WM_LBUTTONUP messages are registered but the previous WM_NOTIFY handler is not overwritten.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