繁体   English   中英

如何在C#Windows应用程序中将选中的列表框的选定项添加到datagridview中的特定列?

[英]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();
    }

我认为您没有其他向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();
   }
}

如果检查了其他变体,则可以使用绑定和过滤器值。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM