您现在的位置: 中国男护士网 >> 考试频道 >> 计算机等级 >> 二级辅导 >> VB >> 辅导 >> 正文    
  一个更好的获得VBListBox的items的方法 【注册男护士专用博客】          

一个更好的获得VBListBox的items的方法

www.nanhushi.com     佚名   不详 

  A better way to gather multi-selected Visual Basic ListBox items

  Conventional Visual Basic wisdom states that in order to gather the selected items from a multi-select ListBox, you should loop through all the items and test the Selected property. As with all loops, however, this can potentially bog down slower CPU注释:s. As a mUCh faster and more elegant alternative, you can use the SendMessage() API function instead.

  As you probably know, this function lets you send a message to one or more windows. The declaration statement conforms to the following syntax:

  Private Declare Function SendMessage Lib "user32" _
  Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg _
  As Long, ByVal wParam As Long, lParam As Any) As Long

  Since we want to gather the listbox注释:s selected items, we注释:ll send the LB_GETSELITEMS constant in the wMsg argument, which you declare like so:

  Private Const LB_GETSELITEMS = &H191

  In essence, the LB_GETSELITEMS message fills an array with the index numbers of all the selected items. As a result, you must pass two additional arguments   with SendMessage(). The first argument should contain the maximum number of selected items. To retrieve this value, you can simply use the listbox注释:s SelCount property. The second argument should hold the array variable you want to fill with index values. The following example shows how you might use this function:

  Dim ItemIndexes() As Long, x As Integer, iNumItems As Integer
  iNumItems = ThisBox.SelCount
  If iNumItems Then
  ReDim ItemIndexes(iNumItems - 1)
  SendMessage ListBox1.hwnd, LB_GETSELITEMS, iNumItems, _
  ItemIndexes(0)
  End If
  For x = 0 To iNumItems - 1
  MsgBox ListBox1.List(ItemIndexes(x))
  Next x

  After being passed to the SendMessage function, iNumItems holds the total number of selected items, and the ItemIndexes array holds the selected item index values. Notice, that you must pass a pointer to the ItemIndexes array, and not the array itself. Thus, we passed ItemIndexes(0) into the SendMessage function, not ItemIndexes().

 

文章录入:杜斌    责任编辑:杜斌 
  • 上一篇文章:

  • 下一篇文章:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
     

    联 系 信 息
    QQ:88236621
    电话:15853773350
    E-Mail:malenurse@163.com
    免费发布招聘信息
    做中国最专业男护士门户网站
    最 新 热 门
    最 新 推 荐
    相 关 文 章
    没有相关文章
    专 题 栏 目

      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)                            【进男护士社区逛逛】
    姓 名:
    * 游客填写  ·注册用户 ·忘记密码
    主 页:

    评 分:
    1分 2分 3分 4分 5分
    评论内容:
  • 请遵守《互联网电子公告服务管理规定》及中华人民共和国其他各项有关法律法规。
  • 严禁发表危害国家安全、损害国家利益、破坏民族团结、破坏国家宗教政策、破坏社会稳定、侮辱、诽谤、教唆、淫秽等内容的评论 。
  • 用户需对自己在使用本站服务过程中的行为承担法律责任(直接或间接导致的)。
  • 本站管理员有权保留或删除评论内容。
  • 评论内容只代表网友个人观点,与本网站立场无关。