Indexed Property

  • Thread starter Thread starter Altman
  • Start date Start date
A

Altman

I would like to use an indexed property to access my private array of user
controls. If I don't use an indexed property, the property will show up in
my Properties Window during development. Is there a way to get this to show
up in the properties window?
 
This may help: If you use a Collection (collection of control object) behind
the property instead of an indexed property you will see a collection editor
automatically come up in the property grid. A strongly typed collection is
the more OO approach and you will automatically get other functionality from
..NET at design time and runtime.


--
Mike

Mike McIntyre
Visual Basic MVP
www.getdotnetcode.com
 
Ok I have been kind of looking at that in the help. I got the collection to
show in the properties but how can I set the variable type that can be added
to the collection? This is what I have so far.
Private widget As New Collection

Public Property mywidget() As Collection

Get

Return widget

End Get

Set(ByVal Value As Collection)

widget = Value

End Set

End Property
 
To do this you must use a strongly typed collection.

You may want to read up on strong collections and using the collection
editor in the property grid.
 
Ok I've done that but the only thing I can add in the object collection
editor is system.object. How can I get this to allow me to add objects of
type usercontrol. here is my collection class
Public Sub Add(ByVal newConnection As UserControl)

Me.List.Add(newConnection)

End Sub

Public Sub Remove(ByVal nIndex As Short)

If nIndex <= Count - 1 Or nIndex >= 0 Then

Me.RemoveAt(nIndex)

End If

End Sub

Public Property item(ByVal index) As UserControl

Get

Return CType(List.Item(index), UserControl)

End Get

Set(ByVal value As UserControl)

Me.List.Item(index) = value

End Set

End Property
 
Here is an example of strongly typed collection for type UserControl:

Class UserControlCollection

Inherits System.Collections.CollectionBase

Public Sub New()

MyBase.New()

End Sub

Public Sub New(ByVal useValue As UserControlCollection)

MyBase.New()

Me.AddRange(useValue)

End Sub

Public Sub New(ByVal useValue() As UserControl)

MyBase.New()

Me.AddRange(useValue)

End Sub

Default Public Property Item(ByVal intIndex As Integer) As UserControl

Get

Return CType(List(intIndex), UserControl)

End Get

Set(ByVal Value As UserControl)

List(intIndex) = value

End Set

End Property

Public Function Add(ByVal useValue As UserControl) As Integer

Return List.Add(useValue)

End Function

Public Overloads Sub AddRange(ByVal useValue() As UserControl)

Dim Counter As Integer = 0

Do While (Counter < useValue.Length)

Me.Add(useValue(Counter))

Counter = (Counter + 1)

Loop

End Sub

Public Overloads Sub AddRange(ByVal useValue As UserControlCollection)

Dim Counter As Integer = 0

Do While (Counter < useValue.Count)

Me.Add(useValue(Counter))

Counter = (Counter + 1)

Loop

End Sub

Public Function Contains(ByVal useValue As UserControl) As Boolean

Return List.Contains(useValue)

End Function

Public Sub CopyTo(ByVal useArray() As UserControl, ByVal intIndex As
Integer)

List.CopyTo(useArray, intIndex)

End Sub

Public Function IndexOf(ByVal useValue As UserControl) As Integer

Return List.IndexOf(useValue)

End Function

Public Sub Insert(ByVal intIndex As Integer, ByVal useValue As UserControl)

List.Insert(intIndex, useValue)

End Sub

Public Shadows Function GetEnumerator() As UserControlEnumerator

Return New UserControlEnumerator(Me)

End Function

Public Sub Remove(ByVal useValue As UserControl)

List.Remove(useValue)

End Sub

Public Class UserControlEnumerator

Inherits Object

Implements System.Collections.IEnumerator

Private Base As System.Collections.IEnumerator

Private Local As System.Collections.IEnumerable

Public Sub New(ByVal useMappings As UserControlCollection)

MyBase.New()

Me.Local = CType(useMappings, System.Collections.IEnumerable)

Me.Base = Local.GetEnumerator

End Sub

Public ReadOnly Property Current() As UserControl

Get

Return CType(Base.Current, UserControl)

End Get

End Property

ReadOnly Property System_Collections_IEnumerator_Current() As Object
Implements System.Collections.IEnumerator.Current

Get

Return Base.Current

End Get

End Property

Public Function MoveNext() As Boolean

Return Base.MoveNext

End Function

Function System_Collections_IEnumerator_MoveNext() As Boolean Implements
System.Collections.IEnumerator.MoveNext

Return Base.MoveNext

End Function

Public Sub Reset()

Base.Reset()

End Sub

Sub System_Collections_IEnumerator_Reset() Implements
System.Collections.IEnumerator.Reset

Base.Reset()

End Sub

End Class

End Class

#End Region
 
Thanks for you help this seems to be working. What I was hoping though is
to have a dropdown list of the current controls that are available. I need
this to link to controls that are already out there and not create a new
one. How could I do this?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top