[英]how can i get the selected items of a checked listbox to a particular column in datagridview in c# windows application?
string items;
string total;
private void checkedListBox1_SelectedValueChanged(object sender, EventArgs e)
{
foreach (string index in checkedListBox1.CheckedItems)
{
for (int cnt = 0; cnt < checkedListBox1.Items.Count; cnt++)
// total_items.(getdata.Items[index].ToString());
total = index.ToString();
}
dataGridView1.Columns.Add("Items", "Choosed Items");
dataGridView1.Rows.Add(total);
dataGridView1.ClearSelection();
}
I think you haven`t any other variant for add rows to datagridView. 我认为您没有其他向datagridView添加行的其他变体。
private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
if(listBox1.SelectedIndex != -1) {
// Get the currently selected item in the ListBox.
total = listBox1.SelectedItem.ToString();
dataGridView1.Rows.Add(new object[] {total});
listbox1.ClearSelected();
}
}
Other variant maybe you can use bindings and filter values if it`s checked. 如果检查了其他变体,则可以使用绑定和过滤器值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.