I'm making a WPF project based on an Access database. The database has two tables:
- tblMovies (MovieID: PK, Title, Director, Genre etc)
- tblActors (ActorID: PK, MovieID: FK, Firstname, Lastname etc)
I have listbox where I can see all the movies, and if I click on one, it shows a new window with all the details about that movie: the title, director, genre, but also the actors.
In this window I have added a button to create a new actor. This opens a new window where you can enter the MovieID (FK) and the information about the actor. When I click save changes, it works and the window closes, but my listboxActors needs to be manually refreshed (I have added a button for that) to see the new actor.
Is there a way to refresh my listboxActors after I click "save changes" in my other window?
I first did it by closing my first screen when clicking add new actor, and then if I saved it would reopen the screen, and it'd automatically be refreshed, but I don't want it that way.
My listboxActors:
listBoxActors.ItemsSource = mov.Actors;
Save button (in the other screen)
private void buttonSaveNewActor_Click(object sender, RoutedEventArgs e)
{
Actor act = new Actor();
act.MovieID = Convert.ToInt32(textBoxMovieID.Text);
act.FirstName = textBoxFirstName.Text;
act.LastName = textBoxLastName.Text;
act.Country = textBoxCountry.Text;
act.Born = Convert.ToDateTime(BornDate.SelectedDate);
act.Bio = textBoxBio.Text;
ActorRepository.AddActor(act);
MessageBox.Show("The actor: " + act.FirstName + " " + act.LastName + " has been created");
this.Hide();
}
The refresh button:
private void buttonRefresh_Click(object sender, RoutedEventArgs e)
{
listBoxActors.ItemsSource = null;
listBoxActors.ItemsSource = mov.Actors;
}
Thanks in advance!