This is a migrated thread and some comments may be shown as answers.

Drop Down List using Interface

1 Answer 42 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 30 Sep 2013, 05:09 AM
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 ?

1 Answer, 1 is accepted

Sort by
0
George
Telerik team
answered on 02 Oct 2013, 02:31 PM
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 >>
Tags
DropDownList
Asked by
Daniel
Top achievements
Rank 1
Answers by
George
Telerik team
Share this question
or