Home > Ask the Microsoft .Net Development Experts > Visual Basic .NET Questions & Answers > How do I create a control array in VB.NET?
Ask The Win Development Expert: Questions & Answers
EMAIL THIS

How do I create a control array in VB.NET?

Samuel Colak EXPERT RESPONSE FROM: Samuel Colak

Pose a Question
Other Win Development Categories
Meet all Win Development Experts
Become an Expert for this site


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


>
QUESTION POSED ON: 20 March 2003
How do I create a control array in VB.NET? The control should have the same name and should be referenced by using index. I am working in Windows 2000.

>
OK, first's first, .NET control arrays differ very much from that of former VB6, and to be honest, the reason why was that conceptually, a control was something different than a class.

To create a control array in Visual Basic .NET requires that you now change your perception to seeing that everything is just a class.

The following code will help in resolving your issue -- just change the widget for any class that takes you fancy.

Public Class ControlArrayExample

    Private _mycollection As System.Collections.ArrayList = New System.Collections.ArrayList()

    Public ReadOnly Property Count() As Integer
        Get
            If (Not _mycollection Is Nothing) Then
                Return _mycollection.Count
            End If
            Return 0
        End Get
    End Property

    Public ReadOnly Property Item(ByVal Index As Integer) As Widget
        Get
            If (Index > 0) And (Index <= Me.Count) Then
                Return CType(_mycollection.Item(Index - 1), Widget)
            End If
            Return Nothing
        End Get
    End Property


    Public Sub AddItem(ByVal ValueIn As Widget)

        If (Not _mycollection Is Nothing) Then
            _mycollection.Add(ValueIn)
        End If

    End Sub

    Public Class Widget

        Private _myName As String

        Public Property Name() As String
            Get
                Return _myName
            End Get
            Set(ByVal Value As String)
                _myName = Value
            End Set
        End Property

        Public Sub New()

        End Sub
        Public Sub New(ByVal NameIn As String)
            Me.Name = NameIn
        End Sub

    End Class

End Class

Hope that works out for you.


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
VB.NET
Access VB .NET Windows control on client side
Converting floating values to byte form
Read data from parallel port
Converting EXE-files to VB components
Generating classes like we did in VB6
Manipulating text through VB.NET
Converting Windows applications to VB .NET
How to add a key to a listview item in VB.NET
Accessing .NET components from VBScript
How I can assign an untyped dataset to a typed dataset?

Visual Basic .NET
Access VB .NET Windows control on client side
Drop down list server control creates error message
Converting floating values to byte form
Datagrid issue: 'onselection' is not populating
Read data from parallel port
What is the use of these constructors?
Give me an ODBC connect, with SQL authentication
Converting EXE-files to VB components
Generating classes like we did in VB6
Manipulating text through VB.NET

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary



Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice



Windows Development - White Papers, News and Expert Advice
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2000 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts