如何将我的清单列表框中的清单项目添加到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");
}
}
}