/// <summary> /// Performs custom actions when the check state of an item changes</summary> /// <param name="sender">Sender control</param> /// <param name="e">Event args</param> void listView_ItemCheck(object sender, ItemCheckEventArgs e) { if (m_listView.SortingItems) { return; } if (m_listView.MultiSelect) { m_targetsLastChecked = SelectedTargets.ToList(); } else if (e.NewValue == CheckState.Checked) { m_targetsLastChecked = SelectedTargets.ToList(); } }
/// <summary> /// Performs custom actions when checked state of an item changes</summary> /// <param name="sender">Sender control</param> /// <param name="e">Event args</param> void listView_ItemChecked(object sender, ItemCheckedEventArgs e) { if (m_listView.SortingItems) { return; } if (m_listView.MultiSelect) { var currentSelected = SelectedTargets.ToList(); if (!m_targetsLastChecked.OrderBy(x => x.Endpoint).SequenceEqual(currentSelected.OrderBy(x => x.Endpoint))) { OnSelectedTargetsChanged(new SelectedTargetsChangedArgs(m_targetsLastChecked, SelectedTargets)); } } else { if (e.Item.Checked) { //unchek the rest foreach (ListViewItem item in m_listView.Items) { if ((item != null) && item.Checked && item != e.Item) { item.Checked = false; } } var currentSelected = SelectedTargets.ToList(); if (!m_targetsLastChecked.OrderBy(x => x.Endpoint).SequenceEqual(currentSelected.OrderBy(x => x.Endpoint))) { OnSelectedTargetsChanged(new SelectedTargetsChangedArgs(m_targetsLastChecked, SelectedTargets)); } } } }