private void btn_find_Click(object sender, EventArgs e) { try { //create a dictionary that will contain the location of the student searched for Layout studentDetails = RobotController.FindStudent(root, tb_search.Text); dgv_class.CurrentCell = dgv_class.Rows[studentDetails.Vertical].Cells[studentDetails.Horizontal]; } catch (NullReferenceException) { if (string.IsNullOrWhiteSpace(tb_search.Text)) { MessageBox.Show("Please enter a student name.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { //name has to match and if not show message MessageBox.Show("There is no student with that name, please try again.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } }