[Need Help] A ListView like control

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,530
Location
Lansing, MI; USA
Programming Experience
10+
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:
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
Anyone have a good article or some explanation to how this stuff works?
 
Not sure exactly where your questions are going, the DataGridView control has default support for displaying lists/arrays of custom types when bound to DataSource, where it generates the columns for the public properties of the class.
 
I'm making a custom container control (like a listbox/listview) that will hold and display (draw) the custom item's in it's items collection. The Item's collection can only hold 1 type of object (like the listview) and where I'm stuck is the keeping track of the selected index / selected item and the select item from right-click context menu. I haven't actually changed any of my code from above yet (the christmas holiday) but that's what I'm working on today.
 
Back
Top