Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Object Collection to List<> doesn't work

Tags:

c#

.net

c#-4.0

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> ???

like image 537
ahmadali shafiee Avatar asked Dec 25 '11 08:12

ahmadali shafiee


1 Answers

List<Item> items = this.ChkLsBxItemsToDraw.Items.Cast<Item>().ToList();
like image 87
Mohammad t Avatar answered Oct 10 '22 02:10

Mohammad t