在 C#(win-form) 上制作我的项目时,我遇到了一个问题,我必须在每次单击添加按钮 (button1) 时动态生成 2 个组合框,并且我必须并排绑定第二个组合框随着第一个框的索引更改,从数据库(sql server)中检索数据。这是我的代码,请帮助
int _i = 0;int p = 0; int x=2; int y=0;
private void button1_Click(object sender, EventArgs e)
{
for (int i = p; i < x; i++)
{ ComboBox C1 = new ComboBox();
con.Open();
SqlDataAdapter adp = new SqlDataAdapter("select * from company ",con);
DataSet ds = new DataSet();
adp.Fill(ds, "Company");
C1.DataSource = ds.Tables["Company"];
C1.DisplayMember = "Company_Name";
con.Close();
C1.Location = new Point(160 + x, 30 * p + 10); ;
C1.Name = "Combo - " + p;
C1.Parent = this;
p++;
}
x = x + 2;
y++;
}