Private Sub Command1_click()
dim i as long
end sub

解决方案 »

  1.   

    Private Sub Command1_click()
    dim i,j as long
    for i=0 to list1.listcount-1
    if list1.select(i)=true
    then j=i+1
    end sub
    如果第i项被选中的话就不i的值赋给j
      

  2.   

    Dim n As Integer
    For n = 0 To list1.listcount-1
    If List1.Selected(n) = True Then
    Exit For
    End If
    Next
      

  3.   

    控件有它的现成的属性用selected属性
      

  4.   

    使用API
    Public Const LB_GETCURSEL = &H188
    Public Const LB_GETSELITEMS = &H191
    Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long有两种情况:
    1.单选ListBox
    iSelected=SendMessage(ListBox.hwnd, LB_GETCURSEL, 0, 0)2.复选ListBox
        Dim nSelCount As Integer    nSelCount = ListBox.SelCount    Dim nSelIndex() As Long
        ReDim nSelIndex(1 To nSelCount)    SendMessage ListBox.hwnd, LB_GETSELITEMS, nSelCount, nSelIndex(1)
    所有选中项目保存在数组nSelIndex()中 
      

  5.   


    ListIndex 属性
          返回或设置控件中当前选择项目的索引在设计时不可用。语法object.ListIndex [= index]ListIndex 属性语法包含下面部分:部分 描述 
    object 对象表达式,其值是“应用于”列表中的一个对象。 
    index 数值表达式,指定当前项目的索引,“设置值”中有详细说明。 
    设置值index 的设置值为:设置值 描述 
    -1 (ComboBox、DirListBox 和 DriveListBox 控件的缺省值)表示当前没有选择项目;对于 ComboBox 控件,表示用户向文本框部分输入了新文本;对于 DirListBox 控件,表示当前路径的索引。对 DriveListBox 控件,表示在运行时创建该控件时的当前驱动器的索引。 
    n (FileListBox 和 ListBox 控件的缺省值)表明当前选择项目的索引。 
    说明 表达式 List(List1.ListIndex) 返回当前选择项目的字符串。列表中的第一项是 ListIndex = 0,ListCount 始终比最大的 ListIndex 值大 1。对于可以做多重选择的控件,该属性的行为取决于所选择项目的个数。如果只选择了一个项目,ListIndex 返回该项目的索引。在多重选择中,ListIndex 返回包含在焦点矩形内的项目的索引,而不管该项目是否被选。