检查列表视图中所有选中或取消选中的项目

Check all items in listview that are checked or uncheck

我有复选框和带复选框的列表视图,如果我必须检查列表视图中的所有项目,则复选框为真或已选中

否则,如果不是所有项目都在列表视图中选中,则复选框为假或未选中

使用 ItemChecked() event of the ListView, which fires whenever a ListViewItem is checked or unchecked, then simply compare the .Count of the ListView.CheckedItems() collection with the .Count of the ListView.Items() 集合:

Private Sub ListView1_ItemChecked(sender As Object, e As ItemCheckedEventArgs) Handles ListView1.ItemChecked
    CheckBox1.Checked = (ListView1.CheckedItems.Count = ListView1.Items.Count)
End Sub

如果 ListView1 中的所有项都被选中,这将使 CheckBox1 被选中,否则它将被取消选中。