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.
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...???
}
you can try the following
List<X> x2 = chkList.CheckedItems.OfType<X>().ToList();
or cast as object
List<object> x2 = chkList.CheckedItems.OfType<object>().ToList();
Here is a way that works for me:
List<X> x2 = new List<X>();
x2 = chkList.CheckedItems.Cast<X>().ToList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With