dimanche 13 décembre 2020

How can I handle this cast exception in C# : system.data.model in system.windows.controls.CheckBox?

This is my model class of analys

public partial class analys
    {
        public int id { get; set; }
        public string name { get; set; }
        public int price { get; set; }
        public bool Type_qualitatif { get; set; }
        public bool Type_quantitatif { get; set; }
        public System.DateTime create_at { get; set; }
        public System.DateTime update_at { get; set; }
        public int sectionId { get; set; }
    
        public virtual section section { get; set; }
    }
}

I create a ListBox which display checkboxes as items, and the content of each one is the name of an analys.

So I am trying to get the content of the checkboxes checked and save them in a list with the code bellow

foreach ( CheckBox item in  _biochimieExam.BiochimieExamsItemsControl.Items )
             {
                 if(item.IsChecked == true)
                 {
                   //  String exam = item.Content.ToString();
                     SelctedItems.Add(item.Content.ToString());
                 }
             } 
            
            foreach(String item in SelctedItems)
            {
                BchExamsList.Add(new analys
                {
                    name = item
                }) ;
            }

But I'm getting an inavlid cast exception Impossible to cast an object of type 'System.Data.Entity.DynamicProxies.analys_F69488E20B133B223573E1D5931B83214F85574493596933EB8BFDBD5F513C59' in type 'System.Windows.Controls.CheckBox'.' which I try to resolve. But a I failed.

Please I need some help. Thanks.




Aucun commentaire:

Enregistrer un commentaire