private void UpdateList(bool TryKeepOldSelection) { if (SupressUpdate) { return; } try { SupressUpdate = true; string current_value = ""; if (this.SelectedRows.Count == 1) { this.CurrentCell = this[1, this.SelectedRows[0].Index]; } if (TryKeepOldSelection && this != null && this.CurrentCell != null && !this.CurrentRow.IsNewRow) { current_value = this[1, this.CurrentRow.Index].Value.ToString(); } SupressUpdate = false; this.ClearSelection(); this.Rows.Clear(); SupressUpdate = true; Search.PerformSearchToDataGridView(this); this.Sort(this.Columns[1], ListSortDirection.Ascending); if (TryKeepOldSelection && current_value != "") { Application.DoEvents(); this.ClearSelection(); int foundrow = -1; if ((foundrow = this.FindFirstRow(current_value, 1)) >= 0) { SupressUpdate = false; this.CurrentCell = this[1, foundrow]; this.CurrentCell.Selected = true; return; } } else { SupressUpdate = false; this.CurrentCell = this[1, 0]; this.ClearSelection(); } } finally { SupressUpdate = false; } }
private void UpdatePieceList(bool TryKeepOldSelection) { if (SupressUpdate) { return; } DateTime then, now; then = DateTime.Now; try { SupressUpdate = true; this.Cursor = Cursors.WaitCursor; change_status("Updating pieces list...", false); pieceSearch.ClearFilters(); string current_value = ""; if (dg.SelectedRows.Count == 1) { dg.CurrentCell = dg[1, dg.SelectedRows[0].Index]; } if (TryKeepOldSelection && dg != null && dg.CurrentCell != null && !dg.CurrentRow.IsNewRow) { current_value = dg[1, dg.CurrentRow.Index].Value.ToString(); } Application.DoEvents(); SupressUpdate = false; dg.ClearSelection(); dg.Rows.Clear(); SupressUpdate = true; if (txbComposer.SelectedValue != null) { pieceSearch.AddFilter(PieceSearch.Fields.ComposerID, "= " + txbComposer.SelectedValue.ToString()); } else if (txbComposer.HasText()) { return; } if (txbGenre.SelectedValue != null) { pieceSearch.AddFilter(PieceSearch.Fields.GenreID, "= " + txbGenre.SelectedValue.ToString()); } else if (txbGenre.HasText()) { return; } if (txbFilter.Text != TextBoxDefaultNone) { pieceSearch.AddWordFilter(PieceSearch.Fields.MatchName, txbFilter.Text); } pieceSearch.PerformSearchToDataGridView(dg); dg.Sort(dg.Columns[1], ListSortDirection.Ascending); if (TryKeepOldSelection && current_value != "") { Application.DoEvents(); dg.ClearSelection(); int foundrow = -1; if ((foundrow = dg.FindFirstRow(current_value, 1)) >= 0) { SupressUpdate = false; dg.CurrentCell = dg[1, foundrow]; dg.CurrentCell.Selected = true; return; } } else { SupressUpdate = false; dg.CurrentCell = dg[1, 0]; dg.ClearSelection(); } } finally { now = DateTime.Now; SupressUpdate = false; this.Cursor = Cursors.Default; change_status("Search took " + Math.Round((now - then).TotalSeconds, 3) + "s for " + (dg.Rows.Count - 1) + " results"); Application.DoEvents(); } }