Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I am having a List of type X. X is a Property Level Class.
Now on an event i need the CheckedListBox Selected Items into another List<X>.

How to get the output...??
The code i tried is given below...

C#
public void Initialize(List<X> x1)
    {
            chkList.DataSource = x1;
            chkList.DisplayMember = "MeterName"; // MeterName is a property in Class X
            chkList.ValueMember = "PortNum"; // PortNum is a property in Class X
    }

    private void Click_Event(object sender, EventArgs e)
    {

    List<X> x2 = new List<X>();
    // Here I want to get the checkedListBox selected items in x2;
    // How to get it...???

    }
Posted

C#
private void Click_Event(object sender, EventArgs e)
    {

    var x2 = new List<X>();
    foreach (X item in chkList.CheckedItems)
    {
        x2.Add(item);
    }
}
 
Share this answer
 
v2
Comments
Shahin Khorshidnia 19-Dec-12 1:22am    
+5
Hi, try this
C#
 List<x> x2 = new List<x>();
foreach (ListItem Ck in chkbl.Items)
        {
            if (Ck.Selected == true)
            {             
            
x2.add(Ck.Text.ToString().Trim()); 
            }
        }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900