請注意 勾選框若要有反應 .Checked = True
.Selected = True 好像是用在無 CheckBox的狀態,不可與之混淆
MsgBox(ListView1.SelectedItems.Count)' 取得被選取的項目數量
MsgBox(ListView1.CheckedItems.Count) ' 取得被勾選的項目數量
'全選 / 全不選 ListView1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' / 全不選
If Button1.Text = "全選" Then
ListView1.MultiSelect = True '允許 多選
For Each item As ListViewItem In ListView1.Items
item.Checked = True '勾選框才有反應
item.Selected = True'選取項目才有反應
Next
Button1.Text = "全不選"
Else
ListView1.MultiSelect = True '允許 多選
For Each item As ListViewItem In ListView1.Items
item.Checked = False '勾選框才有反應
item.Selected = FalseTrue'選取項目才有反應
Next
Button1.Text = "全選"
End If
End Sub
沒有留言:
張貼留言