2017-10-06 66 views
0

如果ListBoxProjects中有多個選擇,我想以下代碼會打開MsgBox警告。如果列表框中有多個選擇,MsgBox會打開

但是,如果只有一個選擇,它也會打開MsgBox。如果沒有選擇,它不會打開MsgBox。位卡在這一個,任何幫助感激地收到。

If Me.ListBoxProjects.ListIndex > 1 Then 
MsgBox "You can only edit Projects 1 at a time", vbExclamation, "Project Editing" 
End If 
+0

谷歌是什麼'ListBox.ListIndex'屬性,而你正在做的,找出其他屬性都與ListBox控件 – jsotola

回答

0

ListIndex屬性返回所選項目的位置。 爲了達到你想要的你需要你需要訪問ItemSelected集合的Count屬性。

If ListBoxProjects.ItemsSelected.Count > 1 Then 
    MsgBox "You can only edit Projects 1 at a time", vbExclamation, "Project Editing" 
End If 
+0

我有關會得到一個編譯錯誤:方法或數據成員找不到「.ItemsSelected」 – pwm2017

0

使用Selected屬性數組:

For i = 0 To ListBox1.ListCount - 1 
    If ListBox1.Selected(i) = True Then 
     ' do something 

    End If 
Next i 
相關問題