Torna al Thread
Public Class AttivitaCollection
Inherits BindingList(Of Attivita)
Protected _adapter As AdapterAttivita
'Variabili per l'ordinamento
Private _Direction As ListSortDirection = ListSortDirection.Ascending
Private _SortProperty As PropertyDescriptor
Sub New()
Try
_adapter = New AdapterAttivita()
Catch ex As Exception
Throw ex
End Try
Popola()
Me.AllowNew = True
End Sub
Public Overloads Sub AddNew(ByVal sender As Object, ByVal e As System.ComponentModel.AddingNewEventArgs) Handles Me.AddingNew
Me.Items.Add(New Attivita(CType(_adapter.AddAttivita(), IAttivitaDB)))
End Sub
Protected Overridable Sub Popola()
For Each at As IAttivitaDB In _adapter.GetAttivita()
Me.Items.Add(New Attivita(CType(at, IAttivitaDB)))
Next
End Sub
Public Sub Update()
_adapter.Update()
Popola()
End Sub
'Indica che è una collection Ordinabile
Protected Overrides ReadOnly Property SupportsSortingCore() As Boolean
Get
Return True
End Get
End Property
Protected Overrides ReadOnly Property SortPropertyCore() As System.ComponentModel.PropertyDescriptor
Get
Return _SortProperty
End Get
End Property
Protected Overrides ReadOnly Property SortDirectionCore() As System.ComponentModel.ListSortDirection
Get
Return _Direction
End Get
End Property
Protected Overrides Sub ApplySortCore(ByVal prop As System.ComponentModel.PropertyDescriptor, ByVal direction As System.ComponentModel.ListSortDirection)
Dim items As List(Of Attivita) = CType(Me.Items, List(Of Attivita))
_Direction = direction
_SortProperty = prop
If (Not (items) Is Nothing) Then
Select Case prop.DisplayName
Case "Inizio"
items.Sort(New Attivita.InizioComparer(direction))
End Select
End If
End Sub
Protected Overrides Sub RemoveSortCore()
MyBase.RemoveSortCore()
End Sub
Protected Overrides Sub OnListChanged(ByVal e As System.ComponentModel.ListChangedEventArgs)
MyBase.OnListChanged(e)
End Sub
End Class