Click here to Skip to main content
12,817,428 members (37,775 online)
Rate this:
Please Sign up or sign in to vote.
See more: C#
I have a dataGridView1 with dataSource which is reprezented by object IProcedure (interface), it has 2 properties, String Name and int loadRatio. I am trying to update dataSource with objects from collection IProcedures, but it throws this error: ArgumentException: The value "Data_Layer.Procedures.Create_Team" is not of type "Data_Layer.Procedures.Commit_Team" and cannot be used in this generic collection.
Parameter name: value

Commit_Team implements IProcedure and also Create_Team implements IProcedure.

Error at:
iProcedureBindingSource.DataSource = ProceduresToSelect.Values;

public Dictionary<String, IProcedure> Procedures { get; set; }
        public Dictionary<String, IProcedure> ProceduresToSelect { get; set; }

        public Form1()
            cbProcedure.SelectionChangeCommitted +=new EventHandler(cbProcedure_SelectionChangeCommitted);
            Procedures = new Dictionary<string,IProcedure>();
            Procedures.Add("Commit_Team", (IProcedure)new Commit_Team(50));
            Procedures.Add("Create_Team", (IProcedure)new Create_Team(50));
            Procedures.Add("Create_Tournament", (IProcedure)new Create_Tournament(25));
            Procedures.Add("Decline_Team", (IProcedure)new Decline_Team(50));
            Procedures.Add("Player_Registration", (IProcedure)new Player_Registration(30));
            Procedures.Add("Select_Free_Players", (IProcedure)new Select_Free_Players(70));
            Procedures.Add("Select_New_Tournaments", (IProcedure)new Select_New_Tournaments(50));
            Procedures.Add("Select_Player_Detail", (IProcedure)new Select_Player_Detail(70));
            Procedures.Add("Select_Player_Ranking", (IProcedure)new Select_Player_Ranking(70));
            Procedures.Add("Select_Registrations_to_Tournament", (IProcedure)new Select_Registrations_to_Tournament(50));
            Procedures.Add("Select_Teams", (IProcedure)new Select_Teams(70));
            Procedures.Add("Select_Tournmaments", (IProcedure)new Select_Tournaments(50));
            Procedures.Add("Tournament_Registration", (IProcedure)new Tournament_Registration(50));
            ProceduresToSelect = new Dictionary<string, IProcedure>(Procedures);
            iProcedureBindingSource.DataSource = ProceduresToSelect.Values;


Could anyone solve this error?

-Pepin z Hané
Posted 10-Nov-12 10:46am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I have solved it, easy like a slap...

iProcedureBindingSource.DataSource = ProceduresToSelect.Values.ToList<IProcedure>();

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

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170308.1 | Last Updated 10 Nov 2012
Copyright © CodeProject, 1999-2017
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