CheckedListBox与下拉框联动代码



private void yewubind(string id) { //给业务类型下拉框绑定业务类型数据 DataTable dtyewu = sb.SelectLast(id, 0); bool flag = false; foreach (Control con in panel1.Controls) { if (con.Name == id) { con.Visible = true; flag = true; if (dtyewu.Rows.Count > 0) { } else { ((CheckedListBox)con).DataSource = null; } } else { con.Visible = false; } } if (!flag) { CheckedListBox clb_yewu = new CheckedListBox(); clb_yewu.Name = id; clb_yewu.Visible = true; if (dtyewu.Rows.Count > 0) { clb_yewu.DataSource = dtyewu; clb_yewu.DisplayMember = "name"; clb_yewu.ValueMember = "id"; } Size ss = new Size(200, 100); clb_yewu.Size = ss; panel1.Controls.Add(clb_yewu); } } private void cbb_jrh_SelectedIndexChanged(object sender, EventArgs e) { yewubind(cbb_jrh.SelectedValue.ToString()); }

combobox联动 

            DataTable dtjrh = sb.SelectSyscode(2, true);

            if (dtjrh.Rows.Count > 0)

            {

                cbb_jrh.DataSource = dtjrh;

                cbb_jrh.DisplayMember = "name";

                cbb_jrh.ValueMember = "id";

                this.cbb_jrh.SelectedIndex = 0;

            }

            yewubind(cbb_jrh.SelectedValue.ToString());

  

获取选中项 

   foreach (Control c in panel1.Controls)

                {

                    foreach (DataRowView dr in ((CheckedListBox)c).CheckedItems)

                    {

                        yewuid += dr["id"].ToString() + ";";

                    }

                }

  最后清空

 panel1.Controls.Clear();

   this.cbb_jrh.SelectedIndex = 0;

  

你可能感兴趣的:(checked)