private void groupListView_ItemCheck(object sender, ItemCheckEventArgs e) { // A checkbox will be checked/unchecked soon.... try { ListViewItem currentItem = groupListView.Items[e.Index]; PCH.InstallGroup currentGroup = (PCH.InstallGroup)currentItem.Tag; if (e.NewValue == CheckState.Unchecked && PCH.REQUIRED_GROUP_NAME.Equals(currentGroup.name)) { e.NewValue = e.CurrentValue; } else if (!PCH.REQUIRED_GROUP_NAME.Equals(currentGroup.name)) { if (e.NewValue == CheckState.Checked) { // Checks required group string requiredGroupName = currentGroup.parentName; if (!string.IsNullOrEmpty(requiredGroupName) && groupListView.Items.ContainsKey(requiredGroupName)) { ListViewItem searchedItem = groupListView.Items[requiredGroupName]; if (!searchedItem.Checked) { searchedItem.Checked = true; } } // Unchecks all excluded groups Collection <string> excludedGroups = currentGroup.excludedGroupNames; foreach (string anotherGroupName in excludedGroups) { if (!string.IsNullOrEmpty(anotherGroupName) && groupListView.Items.ContainsKey(anotherGroupName)) { ListViewItem searchedItem = groupListView.Items[anotherGroupName]; if (searchedItem.Checked) { searchedItem.Checked = false; } } } } else { // Unchecks all groups depending on it foreach (ListViewItem anotherLvi in groupListView.Items) { if (anotherLvi.Tag != null) { PCH.InstallGroup anotherGroup = (PCH.InstallGroup)anotherLvi.Tag; if (!string.IsNullOrEmpty(anotherGroup.parentName) && anotherGroup.parentName.Equals(currentGroup.name) && anotherLvi.Checked) { anotherLvi.Checked = false; } } } } } } catch (Exception ex) { MessageBoxes.ShowError(this, ex); } }