本文共 923 字,大约阅读时间需要 3 分钟。
对于.NET的CheckedListBox控件,我们可以适当封装,让其可以支持设置CheckListBox中指定Index的某一项的勾选状态的功能,以及支持设置CheckListBox中指定内容的某一项的勾选状态的功能,具体的实现代码如下所示:
' 设置CheckListBox中指定Index的某一项的勾选状态
Function CheckItemByIndex(w_CheckListBox , ItemIndex ,CheckState)
w_CheckListBox.Object.SetItemChecked ItemIndex , CheckState
End Function
RegisterUserFunc "SwfList","CheckItemByIndex","CheckItemByIndex"
' 设置CheckListBox中指定内容的某一项的勾选状态
Function CheckItemByText(w_CheckListBox , ItemText ,CheckState)
For I =0 to w_CheckListBox.GetItemsCount -1
If w_CheckListBox.GetItem(I) = ItemText Then
w_CheckListBox.Object.SetItemChecked I,CheckState
CheckItemByText = True
Exit Function
End If
Next
CheckItemByText = False
End Function
RegisterUserFunc "SwfList","CheckItemByText","CheckItemByText"
在QTP中引用该VBS文件后,可以这样使用封装的功能:
SwfWindow("Form1").SwfList("checkedListBox1").CheckItemByIndex 0,False
Msgbox SwfWindow("Form1").SwfList("checkedListBox1").CheckItemByText ("鸡蛋",True)
转载地址:http://iunli.baihongyu.com/