如何将我的清单列表框中的清单项目添加到DataGridView? [英] How do I add checked item(s) in my checkedlistbox to a DataGridView?
本文介绍了如何将我的清单列表框中的清单项目添加到DataGridView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个下拉列表,用于从数据库中选择类别列表,并将产品名称显示在清单框上。但是,如何将已检查的项目从checkedlistbox抓取到DataGridView?这是我的设计的样子:
I have a dropdownlist that selects category list from Database and display the product name onto the checkedlistbox. But how do I grabs the checked items from the checkedlistbox to the DataGridView? This is how my design looks like:
此外,我如何使已添加到Gridview中的每种药物的默认值均为1?
Also, how do I make every medication that has been added to the Gridview has a default value of 1 Quantity?
推荐答案
将此代码添加到您的添加按钮单击事件中:
Add this code to your Add button click event:
private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < checkedListBox1.Items.Count; i++)
{
if (checkedListBox1.GetItemChecked(i))
{
dataGridView1.Rows.Add(checkedListBox1.Items[i], "1");
}
}
}
这篇关于如何将我的清单列表框中的清单项目添加到DataGridView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文