Option Explicit Dim i As IntegerPrivate Sub Form_Load() List1.AddItem "111" List1.AddItem "222" List1.AddItem "333" List1.Selected(0) = True
End SubPrivate Sub List1_Click() Text1.Text = "" For i = 0 To List1.ListCount - 1 If List1.Selected(i) = True Then Text1.Text = Text1.Text & List1.List(i) End If Next i End Sub
Dim intItem As Integer Dim intCheckItems As Integer
intCheckItems = 0 With lstTest For intItem = 1 To .ListCount If .Selected(intItem) Then intCheckItems = intCheckItems + 1 End If Next End With
MsgBox "总共有 " & CStr(intCheckItems) & " 项被选中。"
在窗体上有一个Listbox和一个CommandButtonPrivate Sub Command1_Click()
Dim i As Integer Dim astr As String
For i = 0 To 9
If List1.Selected(i) Then
astr = astr & CStr(i + 1) & "\"
End If
Next
MsgBox "Item " & astr & " 被选中了"
End SubPrivate Sub Form_Load()
Dim i As Integer
For i = 1 To 10 List1.AddItem "Item " & CStr(i) Next
MsgBox "请选中其中几项,然后按Command1"
End Sub
对不起,有的问题,现更正:Option ExplicitDim intItem As IntegerPrivate Sub Command1_Click() Dim intCheckItems As Integer
intCheckItems = 0 With lstTest For intItem = 1 To .ListCount If .Selected(intItem - 1) Then intCheckItems = intCheckItems + 1 End If Next End With
With lstTest For intItem = 1 To 10 .AddItem String(5, 64 + intItem) .Selected(intItem - 1) = True Next End With
End Sub
被选种的属性是True. listview1.ListItems(1).Checked=True
呵呵,我还是做错了,把要求看成“有多少项选中”,好最后再来一次:Option ExplicitDim intItem As IntegerPrivate Sub Command1_Click() Dim intCheckedItems As Integer Dim strCheckedItems As String
intCheckedItems = 0 strCheckedItems = ""
With lstTest For intItem = 1 To .ListCount If .Selected(intItem - 1) Then intCheckedItems = intCheckedItems + 1 strCheckedItems = strCheckedItems & CStr(intCheckedItems) & " " & .List(intItem - 1) & vbCrLf End If Next End With
Dim i As IntegerPrivate Sub Form_Load()
List1.AddItem "111"
List1.AddItem "222"
List1.AddItem "333"
List1.Selected(0) = True
End SubPrivate Sub List1_Click()
Text1.Text = ""
For i = 0 To List1.ListCount - 1
If List1.Selected(i) = True Then
Text1.Text = Text1.Text & List1.List(i)
End If
Next i
End Sub
Dim intCheckItems As Integer
intCheckItems = 0
With lstTest
For intItem = 1 To .ListCount
If .Selected(intItem) Then
intCheckItems = intCheckItems + 1
End If
Next
End With
MsgBox "总共有 " & CStr(intCheckItems) & " 项被选中。"
Dim i As Integer
Dim astr As String
For i = 0 To 9
If List1.Selected(i) Then
astr = astr & CStr(i + 1) & "\"
End If
Next
MsgBox "Item " & astr & " 被选中了"
End SubPrivate Sub Form_Load()
Dim i As Integer
For i = 1 To 10
List1.AddItem "Item " & CStr(i)
Next
MsgBox "请选中其中几项,然后按Command1"
End Sub
intCheckItems = 0
With lstTest
For intItem = 1 To .ListCount
If .Selected(intItem - 1) Then
intCheckItems = intCheckItems + 1
End If
Next
End With
MsgBox "总共有 " & CStr(intCheckItems) & " 项被选中。"End SubPrivate Sub Form_Load()
With lstTest
For intItem = 1 To 10
.AddItem String(5, 64 + intItem)
.Selected(intItem - 1) = True
Next
End With
End Sub
listview1.ListItems(1).Checked=True
Dim strCheckedItems As String
intCheckedItems = 0
strCheckedItems = ""
With lstTest
For intItem = 1 To .ListCount
If .Selected(intItem - 1) Then
intCheckedItems = intCheckedItems + 1
strCheckedItems = strCheckedItems & CStr(intCheckedItems) & " " & .List(intItem - 1) & vbCrLf
End If
Next
End With
MsgBox "总共有 " & CStr(intCheckedItems) & " 项被选中,选中项为:" & vbCrLf & strCheckedItemsEnd SubPrivate Sub Form_Load()
With lstTest
For intItem = 1 To 10
.AddItem String(5, 64 + intItem)
.Selected(intItem - 1) = True
Next
End With
End Sub
With List1
If .SelCount = 0 Then
MsgBox "没有项目被选中!"
Exit Sub
End If
For i = 0 To .ListCount - 1
If .Selected(i) Then
s = s & .List(i) & vbCrLf
End If
Next i
MsgBox "一共有 " & .SelCount & "个被选中,分别为:" & vbCrLf & s
End With
End SubPrivate Sub Form_Load() Dim i As Long
With List1
For i = 0 To 100
.AddItem i
Next i
End WithEnd Sub