Click here to Skip to main content
15,887,444 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi, im making a windows form which allows users to select films based on a genre. Now, ive made a combo box which gives the users a list of genres, then they select the genre and the films from that genre are displayed in the listbox. I've put the code in correctly and the program compiles ok but when I click on the combo box, the film genres arent displayed. I cant figure out whats wrong with my code, the names are correct and everything.

Heres my code:

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace FilmAndEntertainmentSystem
{
    public partial class FrmFES : Form
    {
        static string ta = null;

        public FrmFES()
        {
            InitializeComponent();
        }

        private void cbxGenre_SelectedIndexChanged(object sender, EventArgs e)
        {
            ta = cbxGenre.SelectedItem.ToString();

            if (ta == "Action/Thriller")
            {
                lbxFilms.Items.Clear();
                lbxFilms.Items.Add("Casino royale");
                lbxFilms.Items.Add("Die Hard");
                lbxFilms.Items.Add("Raiders of the Lost Ark");
            }
            else if (ta == "Sci Fi")
            {
                lbxFilms.Items.Clear();
                lbxFilms.Items.Add("Blade Runner");
                lbxFilms.Items.Add("Star Wars");
                lbxFilms.Items.Add("Star Trek");
            }
            else if (ta == "Horror")
            {
                lbxFilms.Items.Clear();
                lbxFilms.Items.Add("Saw");
                lbxFilms.Items.Add("Psycho");
                lbxFilms.Items.Add("Blade");
            }
            else
            {
                MessageBox.Show("Please select a film genre");
            }


        }
    }
}
Posted
Comments
Sunasara Imdadhusen 10-Feb-11 8:18am    
What will be value of ta?

Try this:

ta = cbxGenre.SelectedText;


Have you considered using the debugger?
 
Share this answer
 
Comments
programmer1234 10-Feb-11 8:51am    
Ok i've fixed now the debugger did find the problem after all.
Sergey Alexandrovich Kryukov 10-Feb-11 11:32am    
Ha-ha. My 5.
--SA
It is difficult to figure out what could be wrong without looking at the code / design that binds genres to the combo.

At best, for a simple example see here[^].
This might give you an idea as to what you might be doing wrong.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900