|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 chenhu1981 于 2018-7-13 10:46 编辑
各位好,小弟有个问题请教,现在我想在textbox中显示选中的listview复选选中的个数,不知道如何操作,烦请各位帮忙看下,谢谢!
Listview 复选问题.zip
(15.69 KB, 下载次数: 5)
- Private Sub UserForm_Initialize()
- Dim Item As ListItem, w As Integer
- With ListView1
- .CheckBoxes = True
- w = .Width / 5
- .ColumnHeaders.Add , , "A", w
- .ColumnHeaders.Add , , "B", w, lvwColumnCenter
- .ColumnHeaders.Add , , "C", w, lvwColumnCenter
- .ColumnHeaders.Add , , "D", w, lvwColumnCenter
- .ColumnHeaders.Add , , "E", w, lvwColumnCenter
- For i = 1 To 10
- Set Item = .ListItems.Add
- Item = "A" & i
- For j = 1 To 4
- Item.SubItems(j) = Choose(j, "B", "C", "D", "E") & i
- Next
- Next
-
- End With
- End Sub
- Private Sub ListView1_ItemCheck(ByVal Item As MSComctlLib.ListItem)
- Dim S$, k, iSum
- With ListView1
- For i = 1 To .ListItems.Count
- If .ListItems(i).Checked Then
- S = S & "、" & i
- End If
- Next
- For Each k In Split(S, "、")
- iSum = iSum + Val(k)
- Next
- TextBox1.Text = iSum
- End With
- If Len(S) = 0 Then
- Me.Caption = "一行也没有选中"
- Else
- Me.Caption = "选中了第" & Right(S, Len(S) - 1) & "行。"
- k = k + 1
- End If
- Label1.Caption = "您当前点击的是第 " & Item.Index & " 行"
- 'TextBox1.Value = Item.Index
- If Item.Checked Then
- Item.ForeColor = vbRed
- For j = 1 To 4
- Item.ListSubItems(j).ForeColor = vbRed
- Next
- Else
- Item.ForeColor = &H80000008
- For j = 1 To 4
- Item.ListSubItems(j).ForeColor = &H80000008
- Next
- End If
- End Sub
复制代码
|
|