关于PB中列表框函数FindItem函数的认识。

在列表框中使用FindItem函数查找某一个值是否在列表中存在,在实际应用中发现FindItem并不是我想要的结果,查看一下帮助发现:
Description

Finds the next item in a ListBox that begins with the specified search text.

Controls

ListBox, DropDownListBox, PictureListBox, and DropDownPictureListBox controls

Syntax

listboxname.FindItem ( text, index )

Argument    Description
listboxname    The name of the ListBox control in which you want to find an item.
text    A string whose value is the starting text of the item you want to find.
index    The number of the item just before the first item to be searched. To search the whole list, specify 0.

Return value
Integer. Returns the index of the first matching item. To match, the item must start with the specified text; however, the text in the item can be longer than the specified text. If no match is found or if an error occurs, FindItem returns -1. If any argument's value is NULL, FindItem returns NULL.
从上面可以看出,查找并不是查找Text值完全匹配或相等的,而是从列表中查找开始部分,只要前面匹配就会返回其节点的值,故使用时 需要小心。

ddlb_1.AddItem('abcdefg')
ddlb_1.AddItem('lkjhgh')

如果想查找列表中是否包含‘lkj’这个节点ddlb_1.FindItem('lkj',0) 此时会返回2,但该节点不是需要选择,所以需要小心。
当然我也可以自己来完成这个功能,如:
String ls_find
Long ll_index,ll_find
For ll_index = 1 To ddlb_1.TotalItems()
    If ddlb_1.Text(ll_index) = ls_find Then
        ll_find = ll_index
    End If
Next
Return ll_find
当然如果列表框不可编辑且列表中元素左边不包含其他元素,这种问题是不会出现的。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值