listview UDF 疑问,求围观
本帖最后由 xiezhuoyi 于 2014-1-30 14:51 编辑刚刚学习到LISTVIEW 碰到一个问题 LISTview 如果用GUICTRLCREATLISTVIEWITEM建立的删除的时候可以正常删除,但是如果通过_GUICTRLLISTVIEW_ADDITEM()建立的,用_GUICtrlListView_DeleteItem($ListView1,1)删除的时候就无法起到删除效果??应该怎么理解?#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <guilistview.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 615, 438, 192, 124)
$ListView1 = GUICtrlCreateListView("", 16, 16, 577, 337)
$Button1 = GUICtrlCreateButton("Button1", 24, 376, 75, 25)
$Button2 = GUICtrlCreateButton("Button2", 120, 376, 75, 25)
$Button3 = GUICtrlCreateButton("Button3", 200, 376, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
_guictrllistview_addcolumn($ListView1,"test1",150)
_guictrllistview_addcolumn($ListView1,"test2",150)
_guictrllistview_addcolumn($ListView1,"test3",150)
_GUICtrlListView_AddItem($ListView1,"item1")
_GUICtrlListView_AddSubItem($ListView1,0,"item1-1",0)
_GUICtrlListView_AddSubItem($ListView1,0,"item1-2",1)
_GUICtrlListView_AddSubItem($ListView1,0,"item1-3",2)
_GUICtrlListView_AddItem($ListView1,"item2")
_GUICtrlListView_AddSubItem($ListView1,1,"item2-1",0)
_GUICtrlListView_AddSubItem($ListView1,1,"item2-2",1)
_GUICtrlListView_AddSubItem($ListView1,1,"item2-3",2)
_GUICtrlListView_AddItem($ListView1,"item3")
_GUICtrlListView_AddSubItem($ListView1,2,"item3-1",0)
_GUICtrlListView_AddSubItem($ListView1,2,"item3-2",1)
_GUICtrlListView_AddSubItem($ListView1,2,"item3-3",2)
;~ Local $i;循环方式添加ITEM-------guictrlcreatlistviewitem()
;~ For $i=1 To 3
;~ GUICtrlCreateListViewItem("item"&$i&"-1|item"&$i&"-2|item"&$i&"-3",$ListView1)
;~ Next
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
_GUICtrlListView_DeleteItem($ListView1,1)
;~ _GUICtrlListView_BeginUpdate($ListView1)
;~
;~ _GUICtrlListView_EndUpdate($ListView1)
;~ _GUICtrlListView_AddItem($ListView1,"item3")
;~ _GUICtrlListView_AddSubItem($ListView1,2,"item3-1",0)
;~ _GUICtrlListView_AddSubItem($ListView1,2,"item3-2",1)
;~ _GUICtrlListView_AddSubItem($ListView1,2,"item3-3",2)
Case $Button2
_GUICtrlListView_DeleteColumn($ListView1,2)
Case $Button3
_GUICtrlListView_DeleteItemsSelected($ListView1)
EndSwitch
WEnd
Case $Button1
$hListView1= ControlGetHandle("Form1", '', $ListView1)
_GUICtrlListView_DeleteItem($hListView1,1)
改成这样 _GUICtrlListView_用的是控件句柄,GUICtrlCreateListView返回的是控件索引 本帖最后由 xiezhuoyi 于 2014-1-30 14:59 编辑
明白了 谢谢指点
------------------------------------------------------
仔细想了下还是不明白呢,如您说的guictrlcreatelistview返回的是控件索引
我用_guictrllistview_additem,和_guictrllistview_addsubitem用控件索引操作的时候是能操作成功的,到_guictrllistview_deleteitem这好像就不行了 是不是只有_guictrllistview_deleteitem是对控件句柄操作的?
也不对,用guictrlcreatelistviewitem创建也是用的控件索引,但是能删除成功,是不是用_guictrllistview_additem,和_guictrllistview_addsubitem的时候发生了改变? 奇怪用您给出的方法确实可以实现 如果说添加前控件句柄=控件索引,添加后就不等了?也想不通,如果成立应该是不能继续添加下面的了 句柄和索引是两码事 本帖最后由 xiezhuoyi 于 2014-1-30 15:17 编辑
大年三十元老也在,先祝您新年快乐 万事如意
刚刚查了帮助手册,发现就如您说的_guictrllistview_是对空间句柄操作的,而guictrlcreatelistview返回是控件ID,
那是为什么我这里_guictrllistview_additem和_guictrllistview_addsubitem用控件ID操作却得到了想要的结果 回复 8# xiezhuoyi
你可以理解为item和listview是两个控件 这几天也在接触listview,有些地方确实不太好理解,比如索引号,刚刚有点入门.帮顶
页:
[1]