Drop Down List using Interface

2 posts, 0 answers
  1. Daniel
    Daniel avatar
    7 posts
    Member since:
    Jul 2013

    Posted 30 Sep 2013 Link to this post

    Does RadDropDownList support List of Interface as its Data Source?

    I have a problem when using one, error is thrown when setting the display member of the drop down list.

    I have an Interface, let's say
    public interface IBase
    {
     string Name { get; set; }
    }

    and this is used in 2 classes
    public class First : IBase
    {
      public string Name { getset; }
    }
    public class Second : IBase
    {
      public string Name { get; set; }
    }

    Now when I try to populate a drop down list using these classes, I get the error of 
    Property accessor 'Name' on object 'TestWinForm.Second' threw the following exception:'Object does not match target type.'

    I tried to populate this by
    private void button5_Click(object sender, EventArgs e)
            {
                IList<First> tests = new List<First>();
                First test = new First();
                test.Name = "Test1";
                tests.Add(test);
                First test2 = new First();
                test2.Name = "Test2";
                tests.Add(test2);
                IList<Second> tests2 = new List<Second>();
                Second test22 = new Second();
                test22.Name = "Test12";
                tests2.Add(test22);
                Second test222 = new Second();
                test222.Name = "Test22";
                tests2.Add(test222);
     
                IList<IBase> all = new List<IBase>();
     
                foreach(var item in tests)
                {
                    all.Add(item);
                }
     
                foreach(var item in tests2)
                {
                    all.Add(item);
                }
     
                radDropDownList1.DataSource = all;
                radDropDownList1.DisplayMember = "Name";
            }


    Any idea why ?
  2. George
    Admin
    George avatar
    500 posts

    Posted 02 Oct 2013 Link to this post

    Hi Daniel,

    Thank you for contacting us.

    I copied the code you provided me with in a new project and did not observe the described behavior. Can you please download the zip file attached below, run the project and let me know of the results. Please note that I am using version 2013 Q2 724. If you are using an older version of our controls I recommend you to upgrade to the latest version and try again.

    If the issue persists I will be glad to be of further assistance.

    Let me know how this worked out for you.

    Regards,
    George
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top