[已解决]请问这个Listview样式怎么使用?
本帖最后由 godhawk 于 2011-12-30 15:56 编辑$LVS_EDITLABELS 0x0200 项目文字可以就地编辑.
但是我用了之后,完全无效果,这个所谓的“就地编辑”,虽然可以像改文件名那样,点击一下再点击一下进行编辑,但是编辑之后一放开又变回原样,完全无法保存……
而且你点击一个多列的文件的后几列,它也会跳回第一列……
这个功能到底怎么才能正常使用呢?#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
Opt('MustDeclareVars', 1)
$Debug_LV = False ; Check ClassName being passed to ListView functions, set to True and use a handle to another control to see it work
_Main()
Func _Main()
Local $hListView
GUICreate("ListView Set Item Count", 400, 300)
$hListView = GUICtrlCreateListView("", 2, 2, 394, 268,$LVS_EDITLABELS)
GUISetState()
; Add columns
_GUICtrlListView_AddColumn($hListView, "Items", 100)
; Add items
_GUICtrlListView_SetItemCount($hListView, 100)
_GUICtrlListView_BeginUpdate($hListView)
For $x = 1 To 100
GUICtrlCreateListViewItem("Item " & $x, $hListView)
Next
_GUICtrlListView_EndUpdate($hListView)
; Loop until user exits
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
EndFunc ;==>_Main 路过,表示关注。 http://www.autoitx.com/forum.php?mod=viewthread&tid=23399 #include <GUIMenu.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
$MyGui = GUICreate('ListView项目重命名例子', 640, 480)
$hListView = _GUICtrlListView_Create($MyGui, '', 5, 5, 630, 460, $LVS_EDITLABELS)
_GUICtrlListView_SetView($hListView, 1)
_GUICtrlListView_EnableGroupView($hListView)
$hImage = _GUIImageList_Create(32, 32, 5, 1)
_GUICtrlListView_SetImageList($hListView, $hImage)
For $i = 0 To 39
_GUIImageList_AddIcon($hImage, 'Shell32.dll', 100 + $i, True)
_GUICtrlListView_AddItem($hListView, 'Item - ' & $i, $i)
$iNumber = _GUICtrlListView_GetCounterPage($hListView) - 1
_GUICtrlListView_InsertGroup($hListView, -1, 1, '')
_GUICtrlListView_SetItemGroupID($hListView, $iNumber, 1)
Next
$iMenu = GUICtrlCreateContextMenu(GUICtrlCreateDummy())
$hMenu = GUICtrlGetHandle(-1)
$iMenuItem0 = GUICtrlCreateMenuItem('运行程序', $iMenu)
$iMenuItem1 = GUICtrlCreateMenuItem('修改名称', $iMenu)
GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
Do
Until GUIGetMsg() = -3
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hListView
Switch $iCode
Case $LVN_BEGINLABELEDITA, $LVN_BEGINLABELEDITW; 开始编辑项目标签
$tInfo = DllStructCreate($tagNMLVDISPINFO, $ilParam)
Return False ; 允许编辑标签
;Return True; 进制编辑标签
Case $LVN_ENDLABELEDITA, $LVN_ENDLABELEDITW
$tInfo = DllStructCreate($tagNMLVDISPINFO, $ilParam)
Local $tBuffer = DllStructCreate("WCHAR Text[" & DllStructGetData($tInfo, "TextMax") & "]", DllStructGetData($tInfo, "Text"))
$sNewItemName = DllStructGetData($tBuffer, "Text")
If $sNewItemName Then
TrayTip('重命名', '新名称:' & $sNewItemName, 1)
Return True
EndIf
; 如果文本非空, 返回真以设置项目标签为编辑的文本, 返回假拒绝
; 如果文本为空忽略返回值
Case $NM_DBLCLK
_Run()
Case $NM_RCLICK
$hMenu = GUICtrlGetHandle($iMenu)
Local $iMenuId = _GUICtrlMenu_TrackPopupMenu($hMenu, $MyGui, -1, -1, 1, 1, 2)
Switch $iMenuId
Case $iMenuItem0
_Run()
Case $iMenuItem1
$aItemIndex = _GUICtrlListView_GetSelectedIndices($hListView, True)
If $aItemIndex Then
_GUICtrlListView_EditLabel($hListView, $aItemIndex)
EndIf
EndSwitch
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
Func _Run()
$aItemIndex = _GUICtrlListView_GetSelectedIndices($hListView, True)
If $aItemIndex Then
$sItemText = _GUICtrlListView_GetItemText($hListView, $aItemIndex)
MsgBox(0, '', $sItemText)
EndIf
EndFunc ;==>_Run
水木子 发表于 2011-11-30 22:36 http://www.autoitx.com/images/common/back.gif
木子这个例子很不错~ 这个例子太强了,而且代码很简洁,感谢感谢! 回复 5# afan
嘿嘿!网络问题多发了一份儿,已经删除了。 非常好的例子,收藏了 回复 7# 水木子
水木子太厉害了
页:
[1]