I'm looking to make a control that displays a collection of a certain type (similar to a ListView). So far I have a class defined with the properties everything needed. Now I'd like to make a control that would graphically display a collection of this class on a form vertically like a ListBox/ListView, I need it to behave like one too, meaning the contextmenu for the selected item works for the single item, the selected item has a border color different from the others and when an item is selected the listview-like control has a selected index changed event that fires. So far I've found out that for the Items of this control I need an ItemCollection that implements these: IList, ICollection, IEnumerable.
VS 2008 added all the required subs and properties (like adding an item, clearing all items, etc) but I'm at a loss as to what I do with these and where my "Items As List(Of PhoneIndoItem)" comes into play. Here's the code so far:
Anyone have a good article or some explanation to how this stuff works?
VS 2008 added all the required subs and properties (like adding an item, clearing all items, etc) but I'm at a loss as to what I do with these and where my "Items As List(Of PhoneIndoItem)" comes into play. Here's the code so far:
VB.NET:
Option Explicit On
Option Strict On
Option Infer Off
Imports System.ComponentModel
Friend Class PhoneInfo
Friend Items As PhoneInfoItemCollection
Friend Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
Items = New PhoneInfoItemCollection
End Sub
End Class
#Region " PhoneInfoItem "
Friend Class PhoneInfoItem
#Region " Variables "
Private _NumberString As String
Private _TypeString As String
#End Region
#Region " Constructors "
Friend Sub New()
_NumberString = String.Empty
_TypeString = String.Empty
End Sub
Friend Sub New(ByVal Number As String, ByVal Type As String)
_NumberString = Number
_TypeString = Type
End Sub
#End Region
#Region " Properties "
Friend Property Number() As String
Get
Return Me._NumberString
End Get
Set(ByVal value As String)
If Me._NumberString <> value Then Me._NumberString = value
End Set
End Property
Friend Property Type() As String
Get
Return Me._TypeString
End Get
Set(ByVal value As String)
If Me._TypeString <> value Then Me._TypeString = value
End Set
End Property
#End Region
End Class
#End Region
#Region " PhoneInfoItemCollection "
Public Class PhoneInfoItemCollection
Implements IList, ICollection, IEnumerable
Private Items As List(Of PhoneInfoItem)
Public Sub CopyTo(ByVal array As System.Array, ByVal index As Integer) Implements System.Collections.ICollection.CopyTo
End Sub
Public ReadOnly Property Count() As Integer Implements System.Collections.ICollection.Count
Get
Return Items.Count
End Get
End Property
Public ReadOnly Property IsSynchronized() As Boolean Implements System.Collections.ICollection.IsSynchronized
Get
End Get
End Property
Public ReadOnly Property SyncRoot() As Object Implements System.Collections.ICollection.SyncRoot
Get
End Get
End Property
Public Function GetEnumerator() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator
End Function
Public Function Add(ByVal value As Object) As Integer Implements System.Collections.IList.Add
End Function
Public Sub Clear() Implements System.Collections.IList.Clear
Items.Clear()
End Sub
Public Function Contains(ByVal value As Object) As Boolean Implements System.Collections.IList.Contains
End Function
Public Function IndexOf(ByVal value As Object) As Integer Implements System.Collections.IList.IndexOf
End Function
Public Sub Insert(ByVal index As Integer, ByVal value As Object) Implements System.Collections.IList.Insert
End Sub
Public ReadOnly Property IsFixedSize() As Boolean Implements System.Collections.IList.IsFixedSize
Get
End Get
End Property
Public ReadOnly Property IsReadOnly() As Boolean Implements System.Collections.IList.IsReadOnly
Get
End Get
End Property
Default Public Property Item(ByVal index As Integer) As Object Implements System.Collections.IList.Item
Get
Return Items(index)
End Get
Set(ByVal value As Object)
If Items(index).Equals(value) = False Then Items(index) = CType(value, PhoneInfoItem)
End Set
End Property
Public Sub Remove(ByVal value As Object) Implements System.Collections.IList.Remove
End Sub
Public Sub RemoveAt(ByVal index As Integer) Implements System.Collections.IList.RemoveAt
End Sub
End Class
#End Region