ITypedList インターフェイス

定義

バインドに利用できるプロパティがバインド先のオブジェクトのパブリック プロパティと異なる場合に、バインド可能リストのスキーマを検出できるようにします。

public interface class ITypedList
public interface ITypedList
type ITypedList = interface
Public Interface ITypedList
派生

ITypedList インターフェイスの実装方法を示すコード例を次に示します。 SortableBindingList という名前のジェネリック型は、BindingList<T> クラスから派生し、ITypedList インターフェイスを実装します。 完全なコード一覧については、「 方法: ITypedList インターフェイスを実装する」を参照してください。

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
    }
}
Imports System.ComponentModel
Imports System.Collections.Generic
Imports System.Windows.Forms

<Serializable()> _
Public Class SortableBindingList(Of Tkey)
    Inherits BindingList(Of Tkey)
    Implements ITypedList

    <NonSerialized()> _
    Private properties As PropertyDescriptorCollection

    Public Sub New()
        MyBase.New()

        ' Get the 'shape' of the list. 
        ' Only get the public properties marked with Browsable = true.
        Dim pdc As PropertyDescriptorCollection = TypeDescriptor.GetProperties(GetType(Tkey), New Attribute() {New BrowsableAttribute(True)})

        ' Sort the properties.
        properties = pdc.Sort()

    End Sub

#Region "ITypedList Implementation"

    Public Function GetItemProperties(ByVal listAccessors() As System.ComponentModel.PropertyDescriptor) As System.ComponentModel.PropertyDescriptorCollection Implements System.ComponentModel.ITypedList.GetItemProperties

        Dim pdc As PropertyDescriptorCollection

        If (Not (listAccessors Is Nothing)) And (listAccessors.Length > 0) Then
            ' Return child list shape
            pdc = ListBindingHelper.GetListItemProperties(listAccessors(0).PropertyType)
        Else
            ' Return properties in sort order
            pdc = properties
        End If

        Return pdc

    End Function

    ' This method is only used in the design-time framework 
    ' and by the obsolete DataGrid control.
    Public Function GetListName( _
    ByVal listAccessors() As PropertyDescriptor) As String _
    Implements System.ComponentModel.ITypedList.GetListName

        Return GetType(Tkey).Name

    End Function

#End Region

End Class

注釈

たとえば、テーブルを表す オブジェクトをDataView使用している場合に、 のプロパティではなく、 が表すオブジェクトDataViewのプロパティにcustomerバインドする場合は、このインターフェイスをDataView使用customerします。

このインターフェイスは、バインド可能なリストのデザイン時のサポートには必要ありません。

データへのバインドは、実行時またはデザイナーで行うことができますが、両方の規則があります。 実行時に、次のいずれかのデータにバインドできます。

  • Array

  • の実装者 IListが厳密に型指定された Item[] プロパティを持っている場合 (つまり、 Type は 以外のすべて Objectです)。 これは、既定の実装 Item[] をプライベートにすることで実現できます。 厳密に型指定されたコレクションの規則に従う を IList 作成する場合は、 から CollectionBase派生する必要があります。

  • ITypedList実装者。

デザイナーでは、同じ規則に従ってオブジェクトへの Component バインドを初期化できます。

データ ソースへのバインドの詳細については、 クラスを System.Windows.Forms.Binding 参照してください。

メソッド

GetItemProperties(PropertyDescriptor[])

データ バインドに使用される各項目のプロパティを表す PropertyDescriptorCollection を返します。

GetListName(PropertyDescriptor[])

リストの名前を返します。

適用対象

こちらもご覧ください