sindhu jampani
sindhu jampani

Reputation: 524

List for both checkedlist box and combobox

I want to add all selected items of checkedlistbox and combobox to a list and use that list in a for each loop in c#

I tried this

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

if (rbtnMultipleScenario.Checked == true)
{
    foreach ( CheckedListBox str in clbScenario.SelectedItems)
    {                    
         lstitems.Add(str);
    }                  
}

By using String, I am not able to add all the selected items of Checkedlistbox.

Which type of list I have to use?

Upvotes: 0

Views: 290

Answers (1)

Antony Koch
Antony Koch

Reputation: 2053

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

if (rbtnMultipleScenario.Checked == true)
{
    foreach ( string str in clbScenario.SelectedItems)
    {                    
         lstitems.Add(str);
    }                  
}

This assumes that SelectedItems contains a collection of strings (which by your exception it does)

Upvotes: 1

Related Questions