private void mediaGridView_CellClick(object sender, DataGridViewCellEventArgs e) { int row = e.RowIndex;//get which row was selected //if user clicks column headers, row = -1, so ignore if (row >= 0) { //cast dataSource from object back into what we put it in List <MediaModel> medias = (List <MediaModel>)mediaGridView.DataSource; //get the individual media selected MediaModel media = medias[row]; selectMediaLable.Text = "Selected Media: " + media.MediaName; selectedMedia = media; selectedReserve = mediaLogic.GetReserved(selectedMedia.MediaId); selectedBorrowed = mediaLogic.GetBorrowed(selectedMedia.MediaId); //Media availability if (mediaLogic.GetReservedByMedia(selectedMedia.MediaId) != null) { availabilityLabel.Text = "Media Availability: Reserved"; reserveButton.Text = "Unreserve";//Changes button text to unreserve } else if (mediaLogic.GetBorrowedByMediaId(selectedMedia.MediaId) != null) { var item = mediaLogic.GetBorrowedByMediaId(selectedMedia.MediaId); if (item.Last().ActualReturnDate < item.Last().BorrowDate) { availabilityLabel.Text = "Media Availability: Borrowed"; } else { availabilityLabel.Text = "Media Availability: Available"; } reserveButton.Text = "Reserve"; } else { availabilityLabel.Text = "Media Availability: Available"; reserveButton.Text = "Reserve"; //Returns button text to reserve } } }