jugador Posted December 7, 2020 Posted December 7, 2020 this example of Listview Edit from @pixelsearch thread expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiEdit.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> ; ############# Global $g_hEdit, $g_sSubItemText_Old = "" Global $g_iItem = -1, $g_iSubItem = -1, $g_iItemEdit = -1, $g_iSubItemEdit = -1 Global $hGUI = GUICreate("Wandering through ListView (901f)", 460, 500) Global $idListView = GUICtrlCreateListView _ (" Col 0 | Col 1| Col 2| Col 3", 15, 60, 430, 400) Global $hListView = GuiCtrlGetHandle($idListView) For $iRow = 0 To 99 $sRow = StringFormat("%2s", $iRow) GUICtrlCreateListViewItem( _ "Row " & $sRow & " / Col 0 |" & _ "Row " & $sRow & " / Col 1 |" & _ "Row " & $sRow & " / Col 2 |" & _ "Row " & $sRow & " / Col 3", $idListView) Next Global $g_iColumnCount = _GUICtrlListView_GetColumnCount($idListView) -1 ; ############# ; ############# Local $Id_ButtonA = GUICtrlCreateButton("Edit", 10, 5, 40, 22) Local $k_Flag = 0 Local $idDummy_Enter = GUICtrlCreateDummy() Local $idDummy_Esc = GUICtrlCreateDummy() Local $aAccelKeys[2][2] = [["{ENTER}", $idDummy_Enter], ["{ESC}", $idDummy_Esc]] GUISetAccelerators($aAccelKeys) ; ############# GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE GUIDelete($hGUI) Exit Case $Id_ButtonA If $k_Flag = 0 Then $k_Flag = 1 Start_Edit() EndIf Case $idDummy_Esc If $k_Flag = 1 Then $k_Flag = 0 If $g_iItemEdit > -1 Then End_Edit(0) EndIf Case $idDummy_Enter If $k_Flag = 1 Then $k_Flag = 0 If $g_iItemEdit > -1 Then End_Edit(1) EndIf EndSwitch WEnd ;===== Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $tNMHDR, $hWndFrom, $iIDFrom, $iCode $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom") $iCode = DllStructGetData($tNMHDR, "Code") Static $bMouseDown = False, $bNotXP = Not (@OSVersion = "WIN_XP") Switch $hWndFrom Case $hListView Switch $iCode Case $NM_CUSTOMDRAW Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam) Local $iDrawStage = DllStructGetData($tCustDraw, "dwDrawStage") If $iDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW If $iDrawStage = $CDDS_ITEMPREPAINT Then Return $CDRF_NOTIFYSUBITEMDRAW Local $iItem = DllStructGetData($tCustDraw, "dwItemSpec") Local $iSubItem = DllStructGetData($tCustDraw, "iSubItem") Local $iColor = 0xFF000000 ; this is $CLR_DEFAULT in ColorConstants.au3 If $iItem = $g_iItem And $iSubItem = $g_iSubItem Then $iColor = 0xFFFFC0 ; light blue for 1 subitem (BGR) EndIf DllStructSetData($tCustDraw, "clrTextBk", $iColor) Return $CDRF_NEWFONT Case $LVN_KEYDOWN If $bMouseDown Or $g_iItem = -1 Then Return 1 ; don't process Local $tInfo = DllStructCreate($tagNMLVKEYDOWN, $lParam) Local $iVK = DllStructGetData($tInfo, "VKey") Switch $iVK Case $VK_RIGHT If $g_iSubItem < $g_iColumnCount Then $g_iSubItem += 1 If $bNotXP Then _GUICtrlListView_RedrawItems($hListview, $g_iItem, $g_iItem) EndIf Case $VK_LEFT If $g_iSubItem > 0 Then $g_iSubItem -= 1 If $bNotXP Then _GUICtrlListView_RedrawItems($hListview, $g_iItem, $g_iItem) EndIf Case $VK_SPACE ; spacebar would select the whole row Return 1 EndSwitch Case $NM_RELEASEDCAPTURE $bMouseDown = True Local $iItemSave = $g_iItem Local $aHit = _GUICtrlListView_SubItemHitTest($hListView) $g_iItem = $aHit[0] $g_iSubItem = $aHit[1] If $g_iItem = -1 And $iItemSave > -1 Then _GUICtrlListView_RedrawItems($hListview, $iItemSave, $iItemSave) EndIf Case $LVN_ITEMCHANGED Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam) Local $iNewState = DllStructGetData($tInfo, "NewState") Switch $iNewState Case BitOr($LVIS_FOCUSED, $LVIS_SELECTED) $g_iItem = DllStructGetData($tInfo, "Item") _GUICtrlListView_SetItemSelected($hListview, $g_iItem, False) EndSwitch Case $NM_CLICK, $NM_RCLICK $bMouseDown = False EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY ;===== Func Start_Edit() If $g_iSubItem <> 0 Then $g_aRect = _GUICtrlListView_GetSubItemRect($hListView, $g_iItem, $g_iSubItem) Else ; column 0 needs _GUICtrlListView_GetItemRect() in case it has been dragged elsewhere (LarsJ) $g_aRect = _GUICtrlListView_GetItemRect($hListView, $g_iItem, 2) ; 2 = bounding rectangle of the item text EndIf $g_iItemEdit = $g_iItem $g_iSubItemEdit = $g_iSubItem $g_sSubItemText_Old = _GUICtrlListView_GetItemText($hListView, $g_iItem, $g_iSubItem) $g_hEdit = _GUICtrlEdit_Create($hListView, $g_sSubItemText_Old, $g_aRect[0], $g_aRect[1], $g_aRect[2]-$g_aRect[0], $g_aRect[3]-$g_aRect[1], BitOR($WS_CHILD, $WS_VISIBLE, $ES_AUTOHSCROLL, $ES_LEFT)) _GUICtrlEdit_SetSel($g_hEdit, 0, -1) ; select all text _WinAPI_SetFocus($g_hEdit) EndFunc ;==>Start_Edit ;===== Func End_Edit($iUpdate_Text) Local $sText = (($iUpdate_Text) ? (_GUICtrlEdit_GetText($g_hEdit)) : ($g_sSubItemText_Old)) _GUICtrlListView_SetItemText($hListView, $g_iItemEdit, $sText, $g_iSubItemEdit) _WinAPI_DestroyWindow($g_hEdit) If $g_iItemEdit <> $g_iItem Or $g_iSubItemEdit <> $g_iSubItem Then _GUICtrlListView_RedrawItems($hListView, $g_iItemEdit, $g_iItemEdit) EndIf $g_iItemEdit = -1 ; -1 means no pending edition (+++) EndFunc ;==>End_Edit Now how I can disable first 3 columns & first 4 rows of the listview from editing.
pixelsearch Posted December 7, 2020 Posted December 7, 2020 Hi jugador If it's gonna be permanent, just add a line in the script (quickly tested) : Case $Id_ButtonA If $g_iItem >= 0 And $g_iItem < 5 And $g_iSubItem >= 0 And $g_iSubItem < 3 Then ContinueLoop jugador 1 "I think you are searching a bug where there is no bug... don't listen to bad advice."
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