public void LoadBookmarks() { int? selectedIndex = null; if (bookMarksLV.SelectedIndices.Count > 0) { selectedIndex = bookMarksLV.SelectedIndices[0]; } bookMarksLV.Items.Clear(); TimeZoneInfo localZone = _replay.Race.Lake.TimeZone; List<Bookmark> bookmarks = GetBookMarks(); if (bookmarks.Count == 0) { Bookmark raceStart = new Bookmark("Race Start", _replay.Race.UtcStart); raceStart.Save(); bookmarks.Add(raceStart); Bookmark raceEnd = new Bookmark("Race End", _replay.Race.UtcEnd); raceEnd.Save(); bookmarks.Add(raceEnd); } foreach (Bookmark b in bookmarks) { string[] subitems = { TimeZoneInfo.ConvertTimeFromUtc(b.Time, localZone).ToLongTimeString(), b.Name }; bookMarksLV.Items.Add(new ListViewItem(subitems)); } if (selectedIndex.HasValue && selectedIndex.Value < bookMarksLV.Items.Count) { bookMarksLV.Items[selectedIndex.Value].Selected = true; } else if (selectedIndex.HasValue && bookMarksLV.Items.Count > 0) { bookMarksLV.Items[bookMarksLV.Items.Count - 1].Selected = true; } else { bookMarksLV_SelectedIndexChanged(null, null); } }
private void addBTN_Click(object sender, EventArgs e) { //get the time first, that way it's not delayed by the amount of time //it takes for the user to enter a name and hit ok. DateTime time = _replay.SimulationTime; NewBookMarkDialog nb = new NewBookMarkDialog(); if (nb.ShowDialog() == DialogResult.OK) { Bookmark b = new Bookmark(nb.BookmarkName, time); b.Save(); LoadBookmarks(); } }