IListSource Interface
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Fornece funcionalidade a um objeto para devolver uma lista que pode ser associada a uma fonte de dados.
public interface class IListSource
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
[System.ComponentModel.TypeConverter("System.Windows.Forms.Design.DataSourceConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public interface IListSource
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
[<System.ComponentModel.TypeConverter("System.Windows.Forms.Design.DataSourceConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
type IListSource = interface
Public Interface IListSource
- Derivado
- Atributos
Exemplos
O exemplo de código a seguir demonstra como implementar o IListSource interface. Um componente denominado EmployeeListSource expõe um IList for data binding ao implementar o GetList método. Para uma lista completa de código, veja Como: Implementar a Interface IListSource.
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 => false;
System.Collections.IList IListSource.GetList()
{
BindingList<Employee> ble = DesignMode
? []
: [
new("Aaberg, Jesper", 26000000),
new ("Aaberg, Jesper", 26000000),
new ("Cajhen, Janko", 19600000),
new ("Furse, Kari", 19000000),
new ("Langhorn, Carl", 16000000),
new ("Todorov, Teodor", 15700000),
new ("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
Observações
Normalmente utiliza-se esta interface para devolver uma lista que pode ser associada a uma fonte de dados, a partir de um objeto que não se implementa IList a si próprio.
A ligação a dados pode ocorrer em tempo de execução ou num designer, mas existem regras para cada um. Em tempo de execução, pode vincular dados em qualquer uma das seguintes opções:
Implementador de IList, desde que o implementador tenha uma propriedade fortemente tipada Item[] (ou seja, o Type é qualquer coisa menos Object). Pode conseguir isto tornando a implementação padrão de Item[] privada. Se quiser criar um IList que siga as regras de uma coleção fortemente tipada, deve derivar de CollectionBase.
Implementador de ITypedList.
Num designer, podes inicializar a ligação a Component objetos seguindo as mesmas regras.
Note
Os implementadores de IListSource podem devolver um IList que contém uma coleção de IList objetos.
Propriedades
| Name | Description |
|---|---|
| ContainsListCollection |
Obtém um valor que indica se a coleção é uma coleção de IList objetos. |
Métodos
| Name | Description |
|---|---|
| GetList() |
Devolve e IList que pode ser ligado a uma fonte de dados a partir de um objeto que não implementa um IList a si próprio. |