组合框取决于另一个组合框 [英] Combo box depends on another combo box

查看:91
本文介绍了组合框取决于另一个组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让一个组合框依赖于来自另一个组合框的选择。

每个都连接到一个mysql服务器,这是三个表。

我想要什么a当您选择类型时,它会根据类型填充品牌。一旦你选择品牌做同样的事情并填写模型。这是我上网的代码,但我实施与我合作,但它的剂量。可以是表吗?



I am trying to make a combo box dependant on a selection from another combobox.
Each are connected to a mysql server which is three tables.
what i want a is when you choose type it fills brand depending on the type. and once you choose brand do the same and fill the model. this is the code i got online but i implemented to work with me but it dosent . Can it be the tables?

<br />
<pre>private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)<br />
        {<br />
             MySqlConnection con = new MySqlConnection("datasource=localhost;port=3306;username=root;password=Deprisa!79849;");<br />
            //---comboBox2,3,and 9--- <br />
            <br />
            comboBox3.SelectedIndex = -1;<br />
            //comboBox3.Items.Clear();<br />
            if (con.State == ConnectionState.Closed)<br />
            {<br />
                con.Open();<br />
            }<br />
            if (comboBox2.SelectedValue != null)<br />
            {<br />
                DataView dv = comboBox2.DataSource as DataView;<br />
                dv.RowFilter = "brand = " + comboBox2.SelectedValue.ToString();<br />
<br />
                MySqlCommand cmd = new MySqlCommand("Select * from brand where idtype='" + comboBox2.SelectedItem + "'", con);<br />
                MySqlDataReader rd = cmd.ExecuteReader();<br />
                while (rd.Read())<br />
                {<br />
                    comboBox2.Items.Add(rd[0]);<br />
                }<br />
                rd.Close();<br />
                cmd.Dispose();<br />
            }<br />
        }<br />
<br />
        private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)<br />
        {<br />
            MySqlConnection con = new MySqlConnection("datasource=localhost;port=3306;username=root;password=Deprisa!79849;");<br />
            comboBox9.SelectedIndex = -1;<br />
            //comboBox9.Items.Clear();<br />
<br />
            if (con.State == ConnectionState.Closed)<br />
            {<br />
                con.Open();<br />
            }<br />
<br />
            MySqlCommand cmd = new MySqlCommand("Select distinct(idbrand) from model where idtype='" + comboBox2.SelectedItem + "'", con);<br />
<br />
            MySqlDataReader rd = cmd.ExecuteReader();<br />
<br />
            while (rd.Read())<br />
            {<br />
                comboBox9.Items.Add(rd[0]);<br />
            }<br />
            rd.Close();<br />
            cmd.Dispose();<br />
        }<br />
<br />
<br />
<br />
<br />
</code></pre>

推荐答案

1。显示表结构。

2.将selectedItem替换为SelectedText或SelectedItem.Value



总的来说,放置断点并告诉您任何错误面对。检查所选值中的值,然后查看是否有任何匹配项从数据库中返回..
1. Show the table structure.
2. Replace selectedItem to SelectedText or SelectedItem.Value

Overall, place breakpoints and tell about any errors which you are facing. Check the value in the selected value, then see if there are any matching items being returned from the database at all..


这篇关于组合框取决于另一个组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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