Change the Max Item Count Allowed Property in Most Recent Used Item List : List Yours « Data Structure « VB.Net

VB.Net
1. 2D
2. Application
3. Class
4. Data Structure
5. Database ADO.net
6. Development
7. Event
8. File Directory
9. Generics
10. GUI
11. Language Basics
12. Network Remote
13. Thread
14. Windows System
15. XML
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net Tutorial
VB.Net » Data Structure » List YoursScreenshots 
Change the Max Item Count Allowed Property in Most Recent Used Item List
Change the Max Item Count Allowed Property in Most Recent Used Item List

Imports System
Imports System.Windows.Forms
Imports System.Collections.Generic
Imports System.ComponentModel

Public Class MainClass

   Shared Sub Main()
       Dim the_items As New MostRecentList(Of String)(4)
       the_items.Add("A")
       the_items.Add("B")
       the_items.Add("C")
       the_items.Add("D")
       the_items.Add("D")
       the_items.Add("B")
       the_items.Add("F")

       For i As Integer = To the_items.Count - 1
            Console.WriteLine(the_items.Item(i))
       Next i

       the_items.MaxItems = 2

       Console.WriteLine()

       For i As Integer = To the_items.Count - 1
            Console.WriteLine(the_items.Item(i))
       Next i


   End Sub 

End Class



Public Class MostRecentList(Of ItemType)
    Public Sub New(ByVal max_items As Integer)
        MaxItems = max_items
    End Sub

    Private m_Items As New List(Of ItemType)
    <Description("The items."), _
     Category("Data")> _
    Public Property Item(ByVal index As IntegerAs ItemType
        Get
            Return m_Items(index)
        End Get
        Set(ByVal value As ItemType)
            m_Items(index= value
        End Set
    End Property

    Private m_MaxItems As Integer = 4
    <Description("The maximum number of items in the list."), _
     Category("Data")> _
    Public Property MaxItems() As Integer
        Get
            Return m_MaxItems
        End Get
        Set(ByVal value As Integer)
            m_MaxItems = value

            Do While m_Items.Count > m_MaxItems
                m_Items.RemoveAt(m_Items.Count - 1)
            Loop
        End Set
    End Property

    <Description("The current number of items."), _
     Category("Data")> _
    Public ReadOnly Property Count() As Integer
        Get
            Return m_Items.Count
        End Get
    End Property

    Public Sub Add(ByVal value As ItemType)
        If m_Items.Contains(valueThen m_Items.Remove(value)

        m_Items.Insert(0, value)

        If m_Items.Count > m_MaxItems Then m_Items.RemoveAt(m_Items.Count - 1)
    End Sub

    Public Sub Remove(ByVal value As ItemType)
        m_Items.Remove(value)
    End Sub

    Public Sub RemoveAt(ByVal index As Integer)
        m_Items.RemoveAt(index)
    End Sub
End Class
           
       
Related examples in the same category
1. Your own List Data structureYour own List Data structure
2. Add Item to Most Recent Used Item ListAdd Item to Most Recent Used Item List
3. Remove Item from Most Recent Used Item ListRemove Item from Most Recent Used Item List
4. Store Object in Most Recent Used Item ListStore Object in Most Recent Used Item List
ww__w_._j_a__v_a___2_s._c__o___m___ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.