组合框和列表框不显示数据 [英] Combo box and list box not displaying data

查看:143
本文介绍了组合框和列表框不显示数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在制作一个窗口表单,允许用户根据流派选择电影.现在,香港专业教育学院制作了一个组合框,为用户提供了一个流派列表,然后他们选择了该流派,然后该流派的电影将显示在列表框中.我已经正确输入了代码,并且程序可以正常编译,但是当我单击组合框时,显示了电影体裁.我无法弄清楚我的代码有什么问题,名称正确无误.

这是我的代码:

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:

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");
            }


        }
    }
}

推荐答案

尝试一下:

Try this:

ta = cbxGenre.SelectedText;



您是否考虑过使用调试器?



Have you considered using the debugger?


如果不查看将流派绑定到组合的代码/设计,很难找出可能出问题的地方.

充其量,举一个简单的例子,请参见此处 [ ^ ].
这可能会让您了解您可能在做错什么.
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.


这篇关于组合框和列表框不显示数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆