Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
Hi,
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;
Code:
public Dictionary<String, IProcedure> Procedures { get; set; }
        public Dictionary<String, IProcedure> ProceduresToSelect { get; set; }
 
        public Form1()
        {
            InitializeComponent();
            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));
            cbProcedure.Items.Clear();
            cbProcedure.Items.AddRange(Procedures.Keys.ToArray<string>());
            ProceduresToSelect = new Dictionary<string, IProcedure>(Procedures);
            iProcedureBindingSource.DataSource = ProceduresToSelect.Values;
 
        }
 
Could anyone solve this error?
 
Thanks!
-Pepin z Hané
Posted 10-Nov-12 9:46am

1 solution

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

Solution 1

I have solved it, easy like a slap...
 
iProcedureBindingSource.DataSource = ProceduresToSelect.Values.ToList<IProcedure>();
  Permalink  
v3

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



Advertise | Privacy | Mobile
Web03 | 2.8.141015.1 | Last Updated 10 Nov 2012
Copyright © CodeProject, 1999-2014
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