【发布时间】:2021-10-27 00:55:12
【问题描述】:
我将 CheckBox 控件从数据库动态添加到 FlowLayOutPanel。如何获取和存储所有选定的值?
我的示例代码在这里...
private void dynamicCheck()
{
//throw new NotImplementedException();
DataSet1TableAdapters.tbl_subjects1TableAdapter ta =
new DataSet1TableAdapters.tbl_subjects1TableAdapter();
DataTable dt = ta.GetData();
foreach (DataRow row in dt.Rows)
{
CheckBox chk = new CheckBox();
chk.Width = 90;
chk.Text = row[1].ToString();
chk.CheckedChanged += new
EventHandler(changeCheck);
flowLayoutPanel1.Controls.Add(chk);
}
}
private void changeCheck(object sender, EventArgs e)
{
//throw new NotImplementedException();
CheckBox chk = sender as CheckBox;
if (chk.Checked)
{
//MessageBox.Show("checked item" + chk.Text);
}
}
private void buttonSave_Click(object sender, EventArgs e)
{
}
【问题讨论】:
-
困难、问题或错误是什么?问题是什么?你想让我做什么?保存什么?在哪里?如何?你问像
MyPanel.Controls.OfType<CheckBox>().Where(Checked)这样的东西吗? How do I ask a good question • What topics can I ask about here? • What types of questions should I avoid asking? • Writing the perfect question -
抱歉这个问题。我想获取 checkBox 检查值并存储为列表,并为列表的每个值创建 sql 插入查询。
标签: c# sql-server winforms checkbox foreach