using PropertyDescriptorCollection works in Winforms but not Web Control - how to fix?

admin

Administrator
Staff member
First of all I have a datasource in my winforms project where I needed to bind the text in a checkedlistbox to a nested property in this case the "Name"

object[0] --> type of ILink --> Name = "adobe"

object[1 ]--> type of ILink --> Name = "flash"

To accomplish this I found a smarter guy <a href="http://jopinblog.wordpress.com/category/databinding/" rel="nofollow">here</a> who led me to a structure like with the relevant code in the GetView() method.

The problem is that this doesn't work for a webcontrol , GetView() doesnt get called. So I'd love to know what modifications I would need to support a webcontrol using this method.

Code:
public class ILinkCollection : List&lt;ILink&gt;, ITypedList
{

}

public class ILinkProgramView : IILinkViewBuilder
{
    public PropertyDescriptorCollection GetView()
    {
        List&lt;PropertyDescriptor&gt; props = new List&lt;PropertyDescriptor&gt;();
        IProgramDelegate del = delegate(ILink d)
        {
            return d.Program.Name;
        };
        props.Add(new ILinkProgramDescriptor("FullName", del, typeof(string)));
        del = delegate(ILink dl) { return dl.IsActive; };
        props.Add(new ILinkProgramDescriptor("IsActive", del, typeof(string)));
        PropertyDescriptor[] propArray = new PropertyDescriptor[props.Count];
        props.CopyTo(propArray);
        return new PropertyDescriptorCollection(propArray);
    }
}
public class ILinkProgramDescriptor : PropertyDescriptor
{

}

I then set the datasource like so

Code:
        ILinkCollection iLinkPrograms = new ILinkCollection(new ILinkProgramView());
        clbProgs.DataSource = iLinkPrograms;
        clbProgs.DisplayMember = "FullName";
        clbProgs.ValueMember = "IsActive";