//get from database - DataGridView public static Unavailability_Course FromDatabase(DataGridView datagridView, int i = -1) { if (i == -1) { if (datagridView.CurrentRow != null) { i = datagridView.CurrentRow.Index; } } if (i == -1) { return(null); } if (datagridView[0, i].CellValue() == null || datagridView[1, i].CellValue() == null || datagridView[2, i].CellValue() == null) { return(null); } //new Unavailability_Course string courseCode = datagridView[0, i].CellValue(); string dateString = datagridView[1, i].CellValue(); int timeSlot = int.Parse(datagridView[2, i].CellValue()); Unavailability_Course unavailabilityCourse = Unavailability_Course.FromDatabase(courseCode, dateString, timeSlot); return(unavailabilityCourse); }