private void OpenSelectedPatientProfile() { int id; if (txtFilter.Text == "") { id = patients[dgvPatientInfoDisplay.CurrentRow.Index].Id; } else { id = filteredPatients[dgvPatientInfoDisplay.CurrentRow.Index].Id; } Patient patient = database.loadPatient(id); PatientProfile pp = new PatientProfile(patient); pp.ShowDialog(); }