C# 选中列表框和组合框的列表

C# 选中列表框和组合框的列表,c#,list,combobox,checkedlistbox,C#,List,Combobox,Checkedlistbox,我想将checkedlistbox和combobox的所有选定项添加到一个列表中,并在a中为c中的每个循环使用该列表# 我试过这个 List<String> list=new List<String>(); if (rbtnMultipleScenario.Checked == true) { foreach ( CheckedListBox str in clbScenario.SelectedItems) {

我想将checkedlistbox和combobox的所有选定项添加到一个列表中,并在a中为c中的每个循环使用该列表#

我试过这个

List<String> list=new List<String>();

if (rbtnMultipleScenario.Checked == true)
{
    foreach ( CheckedListBox str in clbScenario.SelectedItems)
    {                    
         lstitems.Add(str);
    }                  
}
List List=新列表();
if(rbtnMultipleScenario.Checked==true)
{
foreach(在clbScenario中选中ListBox str。选择编辑项)
{                    
添加(str);
}                  
}
通过使用字符串,我无法添加Checkedlistbox的所有选定项

我必须使用哪种类型的列表?

list list list=new list();
List<string> list=new List<string>();

if (rbtnMultipleScenario.Checked == true)
{
    foreach ( string str in clbScenario.SelectedItems)
    {                    
         lstitems.Add(str);
    }                  
}
if(rbtnMultipleScenario.Checked==true) { foreach(clbScenario.SelectedItems中的字符串str) { 添加(str); } }

这假设SelectedItems包含一个字符串集合(在您的异常情况下是这样的)

,因为没有重载
列表。添加以
CheckedListBox
为参数的
方法。为什么不尝试使用
.Text
.ValueMember
(存在哪一个)属性呢?实际上,由于“t”的存在,您可以毫无问题地使用列表parameter.Exception------无法将System.String类型的对象强制转换为System.Windows.Forms.CheckedListBox类型您使用哪些对象来构建选择列表框集合(在clbScenario中)?clbScenario.SelectedItems是一个对象的集合-如果您在其中添加了字符串,那么您将获得字符串。我将更新我的回答如何在foreach循环中添加checkedlistbox中的所有选定项?对于字符串,它没有将所有选定项都放入。SelectedItemsCan是否显示将这些项添加到clbScenario以在UI中显示的代码?我想知道你是不是混血儿。