Rahul Rohela Posted June 20, 2006 Posted June 20, 2006 HI, I want to add edit controll in my listView to edit listViewItems... Is it possible..?/ Please help to do the same... Rahul
BigDod Posted June 20, 2006 Posted June 20, 2006 You could always use _GUICtrlListReplaceString Time you enjoyed wasting is not wasted time ......T.S. Elliot Suspense is worse than disappointment................Robert Burns God help the man who won't help himself, because no-one else will...........My Grandmother
GaryFrost Posted June 20, 2006 Posted June 20, 2006 expandcollapse popup#include <GuiConstants.au3> #include <GuiListview.au3> Global Const $DebugIt = 1 Global Const $WM_NOTIFY = 0x004E Global Const $NM_FIRST = 0 Global Const $NM_CLICK = ($NM_FIRST - 2) Global Const $NM_DBLCLK = ($NM_FIRST - 3) Global $ListView = -999 Global $Gui, $editFlag Global $editCtrl = "Edit1";name of the Edit control that pops up when edit a listitem.... _Main() Func _Main() Local $dll Local $Gui = GUICreate("Double Click Demo", 417, 356, 192, 125) $ListView = GUICtrlCreateListView("Items", 10, 10, 300, 200, $LVS_EDITLABELS);Important Style!!! GUICtrlSendMsg($ListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES) ; Populate list and make it wide enough to see For $i = 1 To 10 GUICtrlCreateListViewItem("DoubleClick or press F2, then press Enter", $ListView) Next GUICtrlSendMsg($ListView, 0x101E, 0, -1);$listview, LVM_SETCOLUMNWIDTH, 0, resize to widest value GUISetState(@SW_SHOW) ;Register WM_NOTIFY events GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events") $dll = DllOpen("user32.dll") While 1 $msg = GUIGetMsg() _MonitorEditState($Gui, $editCtrl, $editFlag, $ListView, $dll) Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case Else ;;;;;;; EndSelect WEnd DllClose($dll) EndFunc ;==>_Main Func ListView_Click() ;---------------------------------------------------------------------------------------------- If $DebugIt Then ConsoleWrite (_DebugHeader("$NM_CLICK")) ;---------------------------------------------------------------------------------------------- If ControlCommand($Gui, "", $editCtrl, "IsVisible", "") Then CancelEdit($ListView) $editFlag = 0 EndIf EndFunc ;==>ListView_Click Func ListView_DoubleClick() ;---------------------------------------------------------------------------------------------- If $DebugIt Then ConsoleWrite (_DebugHeader("$NM_DBLCLK")) ;---------------------------------------------------------------------------------------------- Rename($ListView) $editFlag = 1 EndFunc ;==>ListView_DoubleClick ; WM_NOTIFY event handler Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam) #forceref $hWndGUI, $MsgID, $wParam Local $tagNMHDR, $event $tagNMHDR = DllStructCreate("int;int;int", $lParam);NMHDR (hwndFrom, idFrom, code) If @error Then Return $event = DllStructGetData($tagNMHDR, 3) Select Case $wParam = $ListView Select Case $event = $NM_CLICK ListView_Click() Case $event = $NM_DBLCLK ListView_DoubleClick() EndSelect EndSelect $tagNMHDR = 0 $event = 0 $lParam = 0 EndFunc ;==>WM_Notify_Events Func _DebugHeader($s_text) Return _ "!===========================================================" & @LF & _ "+===========================================================" & @LF & _ "-->" & $s_text & @LF & _ "+===========================================================" & @LF EndFunc ;==>_DebugHeader Func _MonitorEditState(ByRef $h_gui, ByRef $editCtrl, ByRef $editFlag, ByRef $ListView, ByRef $dll) Local $pressed = _IsPressedMod($dll) If $editFlag And $pressed = 13 Then; pressed enter Update($h_gui, $editCtrl, $ListView) ElseIf $editFlag And $pressed = 27 Then; pressed esc CancelEdit($ListView) $editFlag = 0 ElseIf Not $editFlag And $pressed = 113 Then; pressed f2 Rename($ListView) $editFlag = 1 EndIf Sleep(50) If ControlCommand($h_gui, "", $editCtrl, "IsVisible", "") Then If $editFlag = 0 Then $editFlag = 1 Rename($ListView) EndIf Else $editFlag = 0 EndIf EndFunc ;==>_MonitorEditState Func Rename(ByRef $ListView) Local $itemIndex = _GUICtrlListViewGetCurSel ($ListView) GUICtrlSendMsg($ListView, $LVM_EDITLABEL, $itemIndex, 0) HotKeySet("{Enter}", "Enter") EndFunc ;==>Rename Func Enter() ; just a dummy function EndFunc ;==>Enter Func Update(ByRef $h_gui, ByRef $editCtrl, ByRef $ListView) Local $newText = ControlGetText($h_gui, "", $editCtrl) Local $item = GUICtrlRead($ListView) GUICtrlSetData($item, $newText) HotKeySet("{Enter}") Send("{Enter}");quit edit mode $editFlag = 0 $update = 0 EndFunc ;==>Update Func CancelEdit(ByRef $ListView) GUICtrlSendMsg($ListView, $LVM_CANCELEDITLABEL, 0, 0) EndFunc ;==>CancelEdit Func _IsPressedMod($dll = "user32.dll") Local $aR, $bRv, $hexKey, $i For $i = 8 To 128 $hexKey = '0x' & Hex($i, 2) $aR = DllCall($dll, "int", "GetAsyncKeyState", "int", $hexKey) If $aR[0] <> 0 Then Return $i Next Return 0 EndFunc ;==>_IsPressedMod SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference.
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