comboBox联动

cboProType--Items集合数据为:

0-其他
1-旅行社协议
2-公司协议
3-VIPCARD
4-INTERNET

//cboProName绑定
private void BindProName()
        {
            conn.Open();
            SqlDataAdapter da = new SqlDataAdapter("select ContractID,ContractName from Contract", conn);
            DataSet ds = new DataSet();
            da.Fill(ds, "ProName");
            cboProName.DisplayMember = "ContractName";//控件显示的值
            cboProName.ValueMember = "ContractID";//控件实际存储的值 协议编号
            cboProName.DataSource = ds.Tables["ProName"];
            conn.Close();
        }
private void cboProName_SelectedIndexChanged(object sender, EventArgs e)
        {//对cboProName实际存储值截取第一个字符
            switch (cboProName.SelectedValue.ToString().Substring(0,1))
            {
                case "0"://当第一个字符为0时,cboProType的文本为0-其他
                    cboProType.Text = (string)cboProType.Items[0];
                    break;
                case "1":
                    cboProType.Text = (string)cboProType.Items[1];
                    break;
                case "2":
                    cboProType.Text = (string)cboProType.Items[2];
                    break;
                case "3":
                    cboProType.Text = (string)cboProType.Items[3];
                    break;
                default:
                    cboProType.Text = (string)cboProType.Items[4];
                    break;
            }
        }
原文地址:https://www.cnblogs.com/tanghb/p/4972316.html