I am doing 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, first name, last name, etc.)
I have a list where I can see all the films, and if I click on it, a new window will appear with all the details about this film: title, director, genre, but also actors.
In this window, I added a button to create a new actor. This opens a new window in which you can enter MovieID (FK) and actor information. When I click save changes, it works and the window closes, but my listboxActors need to be updated manually (I added a button for this) to see the new member.
Is there a way to update my listboxActors after I click βsave changesβ in another window?
At first I did this by closing my first screen when I click on a new actor, and then if I saved it, it will open the screen again and it will be automatically updated, but I do not want this.
My boxActors list:
listBoxActors.ItemsSource = mov.Actors;
Save button (on another 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();
}
Refresh button:
private void buttonRefresh_Click(object sender, RoutedEventArgs e)
{
listBoxActors.ItemsSource = null;
listBoxActors.ItemsSource = mov.Actors;
}
Thanks in advance!
source
share