public void RemoveSelected() { ListViewItem selectedItem = SelectedItems[0]; if (_schedules.ContainsKey(selectedItem)) { HSchedule schedule = _schedules[selectedItem]; if (schedule.IsRunning) { SchedulesRunning--; } schedule.Dispose(); _schedules.Remove(selectedItem); _bySchedule.Remove(schedule); int index = SelectedIndices[0]; _suppressSelectionChanged = (Items.Count > 1); Items.RemoveAt(index); if (Items.Count > 0) { _suppressSelectionChanged = true; Items[index - (index < Items.Count - 1 && index != 0 || index == Items.Count ? 1 : 0)].Selected = true; } } }
public void ToggleSelected() { ListViewItem selectedItem = SelectedItems[0]; if (_schedules.ContainsKey(selectedItem)) { HSchedule schedule = _schedules[selectedItem]; bool shouldStop = (schedule.IsRunning); if (shouldStop) { schedule.Stop(); SchedulesRunning--; } else { schedule.Start(); SchedulesRunning++; } selectedItem.SubItems[4].Text = (shouldStop ? StatusSTOPPED : StatusRUNNING); } }
public void AddSchedule(HSchedule schedule, bool autoStart, string description) { if (_schedules.ContainsValue(schedule)) { return; } var item = new ListViewItem(new string[] { schedule.Packet.ToString(), schedule.Packet.Destination.ToString(), schedule.Burst.ToString(), schedule.Interval.ToString(), autoStart ? StatusRUNNING : StatusSTOPPED }); if (!string.IsNullOrEmpty(description)) { item.ToolTipText = string.Format("Description: {0}\n{1}", description, schedule.Packet); } Focus(); Items.Add(item); _suppressSelectionChanged = Items.Count > 1; item.Selected = true; EnsureVisible(Items.Count - 1); _schedules.Add(item, schedule); _bySchedule.Add(schedule, item); schedule.ScheduleTriggered += OnScheduleTriggered; if (autoStart) { SchedulesRunning++; schedule.Start(); } }