IListSource Interfaccia

Definizione

Consente di fornire a un oggetto le funzionalità per restituire un elenco che possa essere associato a un'origine dati.

public interface class IListSource
public interface IListSource
[System.ComponentModel.TypeConverter("System.Windows.Forms.Design.DataSourceConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public interface IListSource
[System.ComponentModel.TypeConverter("System.Windows.Forms.Design.DataSourceConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public interface IListSource
type IListSource = interface
[<System.ComponentModel.TypeConverter("System.Windows.Forms.Design.DataSourceConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
type IListSource = interface
[<System.ComponentModel.TypeConverter("System.Windows.Forms.Design.DataSourceConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
type IListSource = interface
Public Interface IListSource
Derivato
Attributi

Esempio

Nell'esempio di codice seguente viene illustrato come implementare l'interfaccia IListSource . Un componente denominato EmployeeListSource espone un IList oggetto per il data binding implementando il GetList metodo . Per un elenco di codice completo, vedere Procedura: Implementare l'interfaccia IListSource.

using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;

namespace IListSourceCS
{
    public class EmployeeListSource : Component, IListSource
    {
        public EmployeeListSource() {}

        public EmployeeListSource(IContainer container)
        {
            container.Add(this);
        }

        #region IListSource Members

        bool IListSource.ContainsListCollection
        {
            get { return false; }
        }

        System.Collections.IList IListSource.GetList()
        {
            BindingList<Employee>   ble = new BindingList<Employee>();

            if (!this.DesignMode)
            {
                ble.Add(new Employee("Aaberg, Jesper", 26000000));
                ble.Add(new Employee("Cajhen, Janko", 19600000));
                ble.Add(new Employee("Furse, Kari", 19000000));
                ble.Add(new Employee("Langhorn, Carl", 16000000));
                ble.Add(new Employee("Todorov, Teodor", 15700000));
                ble.Add(new Employee("Verebélyi, Ágnes", 15700000));
            }

            return ble;
        }

        #endregion
    }
}
Imports System.ComponentModel

Public Class EmployeeListSource
    Inherits Component
    Implements IListSource

    <System.Diagnostics.DebuggerNonUserCode()> _
Public Sub New(ByVal Container As System.ComponentModel.IContainer)
        MyClass.New()

        'Required for Windows.Forms Class Composition Designer support
        Container.Add(Me)

    End Sub

    <System.Diagnostics.DebuggerNonUserCode()> _
    Public Sub New()
        MyBase.New()

        'This call is required by the Component Designer.
        InitializeComponent()

    End Sub

    'Component overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing AndAlso components IsNot Nothing Then
            components.Dispose()
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Component Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Component Designer
    'It can be modified using the Component Designer.
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        components = New System.ComponentModel.Container()
    End Sub

#Region "IListSource Members"

    Public ReadOnly Property ContainsListCollection() As Boolean Implements System.ComponentModel.IListSource.ContainsListCollection
        Get
            Return False
        End Get
    End Property

    Public Function GetList() As System.Collections.IList Implements System.ComponentModel.IListSource.GetList

        Dim ble As New BindingList(Of Employee)

        If Not Me.DesignMode Then
            ble.Add(New Employee("Aaberg, Jesper", 26000000))
            ble.Add(New Employee("Cajhen, Janko", 19600000))
            ble.Add(New Employee("Furse, Kari", 19000000))
            ble.Add(New Employee("Langhorn, Carl", 16000000))
            ble.Add(New Employee("Todorov, Teodor", 15700000))
            ble.Add(New Employee("Verebélyi, Ágnes", 15700000))
        End If

        Return ble

    End Function

#End Region

End Class

Commenti

Questa interfaccia viene in genere usata per restituire un elenco che può essere associato a un'origine dati da un oggetto che non implementa IList se stesso.

L'associazione ai dati può verificarsi in fase di esecuzione o in una finestra di progettazione, ma sono disponibili regole per ognuna. In fase di esecuzione, è possibile eseguire il binding ai dati in uno degli elementi seguenti:

  • Array

  • Implementer di IList, a condizione che l'implementatore abbia una proprietà fortemente tipizzata Item[] , ovvero è Type qualsiasi elemento ma Object. A tale scopo, è possibile rendere l'implementazione predefinita di Item[] private. Se si vuole creare un oggetto IList che segue le regole di una raccolta fortemente tipizzata, è necessario derivare da CollectionBase.

  • Implementatore di ITypedList.

In una finestra di progettazione è possibile inizializzare l'associazione agli Component oggetti seguendo le stesse regole.

Nota

Gli implementatori di IListSource possono restituire un oggetto IList che contiene una raccolta di IList oggetti .

Proprietà

ContainsListCollection

Ottiene un valore che indica se la raccolta è una raccolta di oggetti IList.

Metodi

GetList()

Restituisce un oggetto IList che può essere associato a un'origine dati da un oggetto che non implementa un'interfaccia IList.

Si applica a

Vedi anche