private bool SelectRowById(Id id) { if ((dataGridView1.Rows?.Count ?? 0) < 1) { return(false); } bool found = false; foreach (DataGridViewRow row in dataGridView1.Rows) { if (row.Index < 0) // archaic shit { continue; } CitationSelectorModel cit = (CitationSelectorModel)row.DataBoundItem; if ((cit?.Model.Id ?? Id.Empty) == id) // everything is possible { SelectRow(row.Index); found = true; break; } } return(found); }
private void SelectRow(int idx) { dataGridView1.ClearSelection(); dataGridView1.Rows[idx].Selected = true; dataGridView1.CurrentCell = dataGridView1.Rows[idx].Cells[0]; CitationSelectorModel cit = (CitationSelectorModel)dataGridView1.Rows[idx].DataBoundItem; SelectedCitation = (Citation)cit.Model; }