今天写了个小程序,要用到列表查看器控件,却在删除所有项目是总是不能删除,经过与帮助教程的仔细对比,发现用_GUICtrlListView_AddItem()和_GUICtrlListView_AddSubItem()函数添加项目后就不能删除,而用GUICtrlCreateListViewItem()函数添加却可以,不知是我的程序那里写得有问题,望各位指点。
正常的程序如下:#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("测试1", 298, 328, 433, 206)
$ListView1 = GUICtrlCreateListView("Column1|Column2", 8, 8, 281, 273)
$Button1 = GUICtrlCreateButton("生成项目", 32, 288, 73, 25)
$Button2 = GUICtrlCreateButton("清除项目", 152, 288, 65, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $Button1
create()
Case $Button2
_GUICtrlListView_DeleteAllItems($ListView1)
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func create()
Local $i
_GUICtrlListView_DeleteAllItems($ListView1)
For $i=0 To 8
GUICtrlCreateListViewItem($i&"|"&2*$i+1,$ListView1)
Next
EndFunc
以下程序有问题:#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("测试2", 298, 328, 433, 206)
$ListView1 = GUICtrlCreateListView("Column1|Column2", 8, 8, 281, 273)
$Button1 = GUICtrlCreateButton("生成项目", 32, 288, 73, 25)
$Button2 = GUICtrlCreateButton("清除项目", 152, 288, 65, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $Button1
create()
Case $Button2
_GUICtrlListView_DeleteAllItems($ListView1)
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func create()
Local $i
_GUICtrlListView_DeleteAllItems($ListView1)
For $i=0 To 8
_GUICtrlListView_AddItem($ListView1,$i)
_GUICtrlListView_AddSubItem($ListView1,$i,2*$i+1,1)
Next
EndFunc
|