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 나타내는 개체입니다를 customer 속성 바인딩할 하려는 테이블을 customer 개체를 DataView 하지의 속성을 나타냅니다는 DataView합니다.

이 인터페이스에 대 한 디자인 타임 지원 바인딩 가능한 목록 필요 하지 않습니다.

런타임 시 또는 디자이너에서 데이터에 발생할 수 있습니다 하지만 둘 다에 대 한 규칙이 있습니다. 런타임 시 데이터는 다음 중 하나에 바인딩할 수 있습니다.

  • Array

  • 구현자 IList경우 구현자는 강력한 형식의 Item[] 속성 (즉, 합니다 Type 하다는 Object). Item[] 프라이빗을 기본 구현하여 이를 수행할 수 있습니다. 생성 하려는 경우는 IList 는 강력한 형식의 컬렉션 규칙을 따르는에서 파생 되어야 CollectionBase합니다.

  • 구현자 ITypedList합니다.

디자이너에서 바인딩할을 초기화할 수 있습니다 Component 동일한 규칙에 따라 개체입니다.

데이터 원본에는 바인딩에 대 한 자세한 내용은 참조는 System.Windows.Forms.Binding 클래스입니다.

메서드

GetItemProperties(PropertyDescriptor[])

데이터를 바인딩하는데 사용되는 각 항목의 속성을 나타내는 PropertyDescriptorCollection를 반환합니다.

GetListName(PropertyDescriptor[])

해당 목록의 이름을 반환합니다.

적용 대상

추가 정보