locked
wpf listbox change items RRS feed

  • Question

  • Hello,
    I need advice. I have two listboxes. In the first listbox I put my movies from the Web themoviedb.org which collects information about the movie such as movie title, genre, and also whether the movie is added in a favorite playlist based on the check ToggleButton. And my question is how can I change from the second ListBox check togglebutton first ListBox with the film. Thanks a lot 

    Source code : MoviePlexDemo

    Monday, January 25, 2016 7:48 PM

Answers

  • The way you have implemented this, you could set the IsCheckFavoriteMovie property of the corresponding movie in the List collection to false in your "DeleteItemsFavorite" event handler to uncheck the movie in ListBox1. This seems to work:

     private void DeleteItemsFavorite(object sender, RoutedEventArgs e)
            {
                try
                {
                    foreach (object o in ListBox3.SelectedItems)
                    {
    
    
                        string items = (o as FavoriteMovies).NameMovieFav;
                        //this.txt1.Text = items;
                        ListFav.Remove((FavoriteMovies)ListBox3.SelectedItem);
                        XmlDocument xdoc1 = new XmlDocument();
                        xdoc1.Load(cesta1 + "soubor.xml");
                        foreach (XmlNode node in xdoc1.SelectNodes("MoviesData/movies"))
                        {
                            if (node.SelectSingleNode("movie").InnerText == items)
                            {
                                node.ParentNode.RemoveChild(node);
                            }
    
                        }
                        xdoc1.Save(cesta1 + "soubor.xml");
                        LoadFavoritePlayList();
    
                        var movie = List.FirstOrDefault(m => m.NameMovie == items);
                        if (movie != null)
                            movie.IsCheckFavoriteMovie = false;
    
                    }
                }
                catch { }
            }
    


    Hope that helps.

    Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.

    • Marked as answer by ORRNY66 Tuesday, January 26, 2016 10:26 AM
    Monday, January 25, 2016 9:09 PM

All replies

  • >my question is how can I change from the second ListBox check togglebutton first ListBox with the film.

    I don't follow what you mean.

    If you share the object then when you change in either listbox then it'll change in the other.

    So if you bind IsChecked to a bool in whatever object a film is then it'd change in both.


    Hope that helps.

    Technet articles: WPF: Layout Lab; All my Technet Articles

    Monday, January 25, 2016 7:54 PM
  • The way you have implemented this, you could set the IsCheckFavoriteMovie property of the corresponding movie in the List collection to false in your "DeleteItemsFavorite" event handler to uncheck the movie in ListBox1. This seems to work:

     private void DeleteItemsFavorite(object sender, RoutedEventArgs e)
            {
                try
                {
                    foreach (object o in ListBox3.SelectedItems)
                    {
    
    
                        string items = (o as FavoriteMovies).NameMovieFav;
                        //this.txt1.Text = items;
                        ListFav.Remove((FavoriteMovies)ListBox3.SelectedItem);
                        XmlDocument xdoc1 = new XmlDocument();
                        xdoc1.Load(cesta1 + "soubor.xml");
                        foreach (XmlNode node in xdoc1.SelectNodes("MoviesData/movies"))
                        {
                            if (node.SelectSingleNode("movie").InnerText == items)
                            {
                                node.ParentNode.RemoveChild(node);
                            }
    
                        }
                        xdoc1.Save(cesta1 + "soubor.xml");
                        LoadFavoritePlayList();
    
                        var movie = List.FirstOrDefault(m => m.NameMovie == items);
                        if (movie != null)
                            movie.IsCheckFavoriteMovie = false;
    
                    }
                }
                catch { }
            }
    


    Hope that helps.

    Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.

    • Marked as answer by ORRNY66 Tuesday, January 26, 2016 10:26 AM
    Monday, January 25, 2016 9:09 PM