Populating a list box on a windows form in C#

Posted on 2009-04-17
Last Modified: 2013-12-17
I have been able to pass a variable(Genre) to a windows form in C#.  With that variable I call another class which uses that variable to return a list of movie titles from an Access database based on the genre it is in. The correct movie titiles are being returned, but when I try and pass them to the method that populates the form's listbox, nothign happnes.  Here is my code for the form, please let me know if you see anything I can do to fix my problem.  I also attached the file.  I will also attach the data acces files and the classes this form utilizes.
using System;

using System.Collections.Generic;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

namespace FinalProject


    public partial class BrowseTitle : Form


        //Declare variables

        string title = "";

        string genre = "";

        Movie aMovie = new Movie();

        Genre aGenre = new Genre();        

        public ArrayList allTheMovies = new ArrayList();


        public BrowseTitle(string newGenre)




            allTheMovies = Genres.allMovies(newGenre);   <---- here, allTheMovies contains the correct movie objects

            aMovie = (Movie)allTheMovies[0];

            //aGenre = (Genre)allTheMovies[0];

            SetMovieList(aMovie);		<--------------- aMovie is the movie object in position 0 in allTheMovies


        public string Genre


            get { return genre; }

            set { genre = value; }


        private void MovieInfoBtn_Click(object sender, EventArgs e)


            //Declare variable

            title = MovieTitleList.SelectedItem.ToString();


            //Make Movie Info the active form

            MovieInfo movInfo = new MovieInfo(title);




        private void BackBtn_Click(object sender, EventArgs e)


            //Make Browse Genre the active form

            BrowseGenre bGenre = new BrowseGenre();




        private void RentBtn_Click(object sender, EventArgs e)


            //Declare variable

            title = MovieTitleList.SelectedItem.ToString();

            //Pass selection to RentMain

            //Make Rent Main the active form

            RentMain rentM = new RentMain();




        private void SetMovieList(Movie aMovie)		<-------------- aMovie still holds the movie object


            //Movie newMovie = new Movie();                     >               

            this.MovieTitleList.Items.Clear();			>---------------------- Nothing is being passed to these

            foreach (Movie movieTitle in aGenre.AllMovies)	>

                this.MovieTitleList.Items.Add(movieTitle);	>




Open in new window

Question by:udeeze
    LVL 39

    Accepted Solution

    You are passing a single movie to a method that (from the name of it and its contents) should actually receive the whole list. Why are you only passing only a single movie? From that single movie, you can never enter the other movies in the list anymore...

    I don't see the definition of this.MovieTitleList, is that the ListBox? You reference aGenre, but it is not being declared in the scope. Maybe you mean this:

    private void SetMovieList(ArrayList movieList) 
        foreach (Movie aMovie in movieList)

    Open in new window


    Author Closing Comment

    Thank you, that worked great.  I appreciate your quick response.
    LVL 39

    Expert Comment

    > Thank you, that worked great.  I appreciate your quick response.

    glad it helped. I was a bit puzzled by what you meant, but apparently hit it at the right spot ;-)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Normally a window is moved by clicking on the caption bar and dragging. You may want your user to be able to move borderless forms or move a form by clicking anywhere in the form without the limitation to the caption bar. There are many ways to do i…
    Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (…
    This video discusses moving either the default database or any database to a new volume.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now