C#编程中怎样让数据库中一列的数据显示在多个checkbox的标签上? 5
3个回答
展开全部
private DataTable GetTable()
{
DataTable dt = new DataTable();
DataColumnCollection dc = dt.Columns;
dc.Add(new DataColumn("Type", typeof(System.String)));
DataRowCollection dr = dt.Rows;
dr.Add("类型一");
dr.Add("类型二");
dr.Add("类型三");
return dt;
}
private void button1_Click(object sender, EventArgs e)
{
DataTable dt = GetTable();
foreach (DataRow dr in dt.Rows)
{
if (!string.IsNullOrEmpty(dr["Type"].ToString().Trim()))
{
CheckBox cb = new CheckBox();
cb.Text = dr["Type"].ToString().Trim();
flowLayoutPanel1.Controls.Add(cb);
}
}
}
窗体上放一个FlowLayoutPanel
{
DataTable dt = new DataTable();
DataColumnCollection dc = dt.Columns;
dc.Add(new DataColumn("Type", typeof(System.String)));
DataRowCollection dr = dt.Rows;
dr.Add("类型一");
dr.Add("类型二");
dr.Add("类型三");
return dt;
}
private void button1_Click(object sender, EventArgs e)
{
DataTable dt = GetTable();
foreach (DataRow dr in dt.Rows)
{
if (!string.IsNullOrEmpty(dr["Type"].ToString().Trim()))
{
CheckBox cb = new CheckBox();
cb.Text = dr["Type"].ToString().Trim();
flowLayoutPanel1.Controls.Add(cb);
}
}
}
窗体上放一个FlowLayoutPanel
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询