Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# WinForm
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...
 
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 18-Dec-12 18:12pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

private void Click_Event(object sender, EventArgs e)
    {
 
    var x2 = new List<X>();
    foreach (X item in chkList.CheckedItems)
    {
        x2.Add(item);
    }
}
  Permalink  
v2
Comments
Shahin Khorshidnia at 19-Dec-12 1:22am
   
+5
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi, try this
 List<x> x2 = new List<x>();
foreach (ListItem Ck in chkbl.Items)
        {
            if (Ck.Selected == true)
            {             
            
x2.add(Ck.Text.ToString().Trim()); 
            }
        }
  Permalink  
v2

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

  Print Answers RSS
0 OriginalGriff 398
1 Sergey Alexandrovich Kryukov 320
2 Uma Shankar Patel 80
3 CB Sharma 79
4 PhilLenoir 70
0 Sergey Alexandrovich Kryukov 6,532
1 OriginalGriff 5,976
2 CPallini 2,473
3 Richard MacCutchan 1,687
4 Abhinav S 1,550


Advertise | Privacy | Mobile
Web02 | 2.8.140821.2 | Last Updated 19 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100