本帖最后由 jycel 于 2009-9-7 17:44 编辑
如上图!在$Combo内选择数据写入listview中,当列表中已存在相同数据时,该样来判断?
如果有了就不再写入,没有就写入!
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiIPAddress.au3>
#include <GuiStatusBar.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Listview列表数据操作例子", 363, 316, 263, 176)
$ListView1 = GUICtrlCreateListView("", 0, 8, 353, 225,$LVS_EX_GRIDLINES)
_GUICtrlListView_SetExtendedListViewStyle ($ListView1, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_SUBITEMIMAGES))
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50)
_GUICtrlListView_InsertColumn($ListView1, 0, "姓名", 70)
$menu = GUICtrlCreateContextMenu($ListView1)
$del_menu2 = GUICtrlCreateMenuItem("删除", $menu)
$delall_menu2 = GUICtrlCreateMenuItem("清空", $menu)
$Combo1 = GUICtrlCreateCombo("", 16, 240, 137, 25)
GUICtrlSetData(-1,"张三|李四|王麻子|","张三")
$Button1 = GUICtrlCreateButton("添加", 176, 240, 161, 25, $WS_GROUP)
$Label1 = GUICtrlCreateLabel("", 16, 280, 336, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
_GUICtrlListView_AddItem($ListView1,GUICtrlRead($Combo1), 2,0)
Case $del_menu2
$Index = _GUICtrlListView_GetSelectedIndices($ListView1)
If Not StringLen($Index) Then
GUICtrlSetData($Label1,"提示:请选择后再进行删除操作!")
Else
_GUICtrlListView_DeleteItem(GUICtrlGetHandle($ListView1), $Index)
GUICtrlSetData($Label1,"提示:删除成功!")
EndIf
Case $delall_menu2
_GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($ListView1))
EndSwitch
WEnd
|