private void RefreshGrid() { SU.SuspendUpdate.Suspend(this); // Prevent form from repainting while we update the projects try { List <Project> projects = TimeKeeperData.GetActiveProjects(); projects.Sort(); foreach (Row row in this.rows) { row.Refresh(projects); } // Check if there is only a single project entry, if so set it's time if (!this.rows.Any(r => r.TimeIsDirty) && this.rows.Count(r => r.ProjectBox.SelectedItem != null) == 1) { this.rows.Single(r => r.ProjectBox.SelectedItem != null).SetTime(this.MinutesSinceLastSave, false); } this.RollupRows(); } finally { SU.SuspendUpdate.Resume(this); // Ok...we can paint again } }
private void LoadListBox(bool showInactive, long selectedProjectID = 0) { var projects = showInactive ? TimeKeeperData.GetAllProjects() : TimeKeeperData.GetActiveProjects(); projects.Sort(); var previousSelectedIndex = this.lvProjects.SelectedIndices.Count > 0 ? this.lvProjects.SelectedIndices[0] : 0; this.lvProjects.Items.Clear(); this.lvProjects.Items.AddRange(projects.Select(a => new ListViewItem(new string[] { a.Name, a.Department, a.IsActive ? "X" : "" }) { Tag = a }).ToArray()); this.lvProjects.SelectedIndices.Clear(); if (this.lvProjects.Items.Count > previousSelectedIndex) { this.lvProjects.Items[previousSelectedIndex].Selected = true; } else if (this.lvProjects.Items.Count > 0) { this.lvProjects.Items[0].Selected = true; } }