ITypedList Interface

Provides functionality to discover the schema for a bindable list, where the properties available for binding differ from the public properties of the object to bind to.

Namespace:  System.ComponentModel
Assembly:  System (in System.dll)

public interface ITypedList

The ITypedList type exposes the following members.

  NameDescription
Public methodSupported by the XNA FrameworkGetItemPropertiesReturns the PropertyDescriptorCollection that represents the properties on each item used to bind data.
Public methodSupported by the XNA FrameworkGetListNameReturns the name of the list.
Top

Use this interface if, for instance, you are using a DataView object that represents a customer table, you want to bind to the properties on the customer object that the DataView represents, not the properties of the DataView.

This interface is not required for design-time support of a bindable list.

Binding to data can occur either at run time or in a designer, but there are rules for both. At run time, you can bind to data in any of the following:

  • Array

  • Implementer of IList, provided the implementer has a strongly typed Item property (that is, the Type is anything but Object). You can accomplish this by making the default implementation of Item private. If you want to create an IList that follows the rules of a strongly typed collection, you should derive from CollectionBase.

  • Implementer of ITypedList.

In a designer, you can initialize binding to Component objects by following the same rules.

For more information on binding to a data source, see the System.Windows.Forms.Binding class.

The following code example demonstrates how to implement the ITypedList interface. A generic type named SortableBindingList derives from the BindingList<T> class and implements the ITypedList interface. For a full code listing, see How to: Implement the ITypedList Interface.

using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Windows.Forms;
using System.Collections;
using System.Reflection;

namespace ITypedListCS
{
    [Serializable()]
    public class SortableBindingList<T> : BindingList<T>, ITypedList
    {
        [NonSerialized()]
        private PropertyDescriptorCollection properties;

        public SortableBindingList() : base()
        {
            // Get the 'shape' of the list.  
            // Only get the public properties marked with Browsable = true.
            PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(
                typeof(T), 
                new Attribute[] { new BrowsableAttribute(true) });

            // Sort the properties.
            properties = pdc.Sort();
        }

        #region ITypedList Implementation

        public PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[] listAccessors)
        {
            PropertyDescriptorCollection pdc;

            if (listAccessors!=null && listAccessors.Length>0)
            {
                // Return child list shape.
                pdc = ListBindingHelper.GetListItemProperties(listAccessors[0].PropertyType);
            }
            else
            {
                // Return properties in sort order.
                pdc = properties;
            }

            return pdc;
        }

        // This method is only used in the design-time framework  
        // and by the obsolete DataGrid control. 
        public string GetListName(PropertyDescriptor[] listAccessors)
        {   
            return typeof(T).Name;
        }

        #endregion
    }
}

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft