我窗体FORM1上有一个文件列表框file1,有很多文件,其中有一个文件名为ABC,我想在窗体显示时自动让文件名为ABC的这项为选中状态,如果没有文件名为ABC的,则什么都不选,该怎么做????

解决方案 »

  1.   

    '窗体上分别放驱动器列表框,目录列表框,文件列表框
    Option ExplicitPrivate Sub Dir1_Change()
            File1.Path = Dir1.Path
    End SubPrivate Sub Drive1_Change()
            Dir1.Path = Drive1
    End SubPrivate Sub Form_Load()
            Dim i As Integer
            For i = 0 To File1.ListCount - 1
                If InStr(1, File1.List(i), "ABC") > 0 Then
                   File1.Selected(i) = True
                End If
            Next
    End Sub
      

  2.   


    Option ExplicitPrivate Sub Form_Load()
        'File1是文件列表框
        File1.AddItem "sagag"
        File1.AddItem "ABC"
        File1.AddItem "ghg"
        File1.AddItem "jajgopk"
        File1.AddItem "agaga"
        
        
        Dim i As Integer
        For i = 0 To File1.ListCount - 1
            If Trim(File1.List(i)) = "ABC" Then
                File1.Selected(i) = True
                Exit For
            'Else
                '其他操作
            End If
        Next
    End Sub