I have this code for casting CheckedListBox.Items to List<Item>:
List<Item> items = ChkLsBxItemsToDraw.Items as List<Item>;
and this is my Item Class
public class Item
{
public List<double> x = new List<double>();
public List<double> y = new List<double>();
}
I set CheckedListBox.DataSource to a List<Item>
and I got this Error:
Error 1 Cannot convert type ‘
System.Windows.Forms.CheckedListBox.ObjectCollection‘ to ‘System.Collections.Generic.List<Drower.Item>‘ via a reference conversion, boxing conversion, unboxing conversion, wrapping conversion, or null type conversion
How Can I get the CheckedListBox.Items as List<Item> ???
The DataSource and the Items properties are unrelated. The fact that you set the first property doesn’t mean that you will get anything in the second. For example if you check the number of items it will be 0:
ChkLsBxItemsToDraw.Items.Count.You could add elements to the Items property:
and later retrieve them back as a list: