'判断listbox 的取值
Private Sub Command1_Click()
Dim i As Integer
For i = 0 To List1.ListCount - 1
If List1.Selected(i) = True Then
MsgBox List1.List(i)
End If
Next
End Sub
Private Sub Form_Load()
List1.AddItem "啊啊"
List1.AddItem "大的"
List1.AddItem "峨峨"
List1.AddItem "哥哥"
End Sub
谢谢大家的帮助
To:SoHo_Andy(冰)
'判断多选取值的方法
'判断listbox 的取值
Private Sub Command1_Click()
Dim i As Integer
For i = 0 To List1.ListCount - 1
If List1.Selected(i) = True Then
MsgBox List1.List(i)
End If
Next
End Sub
这个会出错!
1.为什么要用CommonDialog1控件,打包的时候要凭空多出一个OCX,几百K,很大的哦,直接用
API就可以实现了,参看:
http://www.mvps.org/vbnet/index.html?code/comdlg/filedlgsoverview.htm
其中这个属性是设置是否允许多文件选择
Public Const OFN_ALLOWMULTISELECT As Long = &H200
2.ListBox可以多选,必须在程序运行之前将ListBox的MultiSelect属性为2.
'判断多选取值的方法
'判断listbox 的取值
Private Sub Command1_Click()
Dim i As Integer
For i = 0 To List1.ListCount - 1
If List1.Selected(i) = True Then
MsgBox List1.List(i)
End If
Next
End Sub