private void mediaGridView_CellContentClick(object sender, DataGridViewCellEventArgs e) { int row = e.RowIndex; if (row > -1)//-1 is the header row, dont care about it { //cast datasource from "object" to list of models. throw exception if not actually //a list of media model List <MediaModel> medias = (List <MediaModel>)mediaGridView.DataSource; selectedMedia = medias.ElementAt <MediaModel>(row);//get from this position titleTextBox.Text = selectedMedia.MediaName; yearTextBox.Text = Convert.ToString(selectedMedia.PublishYear); budgetTextBox.Text = Convert.ToString(selectedMedia.Budget); //this section is made for get the actual value when you select one of your rows genreComboBox.SelectedValue = selectedMedia.getGenre(); languageComboBox.SelectedValue = selectedMedia.getLanguage(); directorComboBox.SelectedValue = selectedMedia.getDirector(); } }
//Media data grid view private void mediaGridView_CellClick(object sender, DataGridViewCellEventArgs e) { int row = e.RowIndex; if (row > 1) { List <MediaModel> medias = (List <MediaModel>)mediaGridView.DataSource; selectedMedia = medias.ElementAt <MediaModel>(row); //Get the individual media selected MediaModel media = medias[row]; selectedMediaLabel.Text = "Selected Media: " + media.MediaName; //Fill form by selecting media titleTextBox.Text = media.MediaName; publishYearTextBox.Text = Convert.ToString(selectedMedia.PublishYear); budgetTextBox.Text = Convert.ToString(selectedMedia.Budget); directorComboBox.SelectedValue = selectedMedia.getDirector(); genreComboBox.SelectedValue = selectedMedia.getGenre(); languageComboBox.SelectedValue = selectedMedia.getLanguage(); } }