By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,373 Members | 1,792 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,373 IT Pros & Developers. It's quick & easy.

Indexed Property

P: n/a
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?
Nov 21 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
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
"Altman" <No******@SickOfSpam.com> wrote in message
news:ew**************@TK2MSFTNGP10.phx.gbl...
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?

Nov 21 '05 #2

P: n/a
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


"Mike McIntyre" <mi****@dotnetshowandtell.com> wrote in message
news:ug**************@TK2MSFTNGP11.phx.gbl...
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
"Altman" <No******@SickOfSpam.com> wrote in message
news:ew**************@TK2MSFTNGP10.phx.gbl...
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?


Nov 21 '05 #3

P: n/a
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.
"Altman" <No******@SickOfSpam.com> wrote in message
news:On**************@TK2MSFTNGP15.phx.gbl...
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


"Mike McIntyre" <mi****@dotnetshowandtell.com> wrote in message
news:ug**************@TK2MSFTNGP11.phx.gbl...
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
"Altman" <No******@SickOfSpam.com> wrote in message
news:ew**************@TK2MSFTNGP10.phx.gbl...
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?



Nov 21 '05 #4

P: n/a
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

"Mike McIntyre" <mi****@dotnetshowandtell.com> wrote in message
news:es**************@TK2MSFTNGP10.phx.gbl...
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.
"Altman" <No******@SickOfSpam.com> wrote in message
news:On**************@TK2MSFTNGP15.phx.gbl...
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


"Mike McIntyre" <mi****@dotnetshowandtell.com> wrote in message
news:ug**************@TK2MSFTNGP11.phx.gbl...
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
"Altman" <No******@SickOfSpam.com> wrote in message
news:ew**************@TK2MSFTNGP10.phx.gbl...
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?



Nov 21 '05 #5

P: n/a
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

"Altman" <No******@SickOfSpam.com> wrote in message
news:O1**************@TK2MSFTNGP11.phx.gbl...
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

"Mike McIntyre" <mi****@dotnetshowandtell.com> wrote in message
news:es**************@TK2MSFTNGP10.phx.gbl...
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.
"Altman" <No******@SickOfSpam.com> wrote in message
news:On**************@TK2MSFTNGP15.phx.gbl...
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


"Mike McIntyre" <mi****@dotnetshowandtell.com> wrote in message
news:ug**************@TK2MSFTNGP11.phx.gbl...
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
"Altman" <No******@SickOfSpam.com> wrote in message
news:ew**************@TK2MSFTNGP10.phx.gbl...
>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?
>



Nov 21 '05 #6

P: n/a
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?

"Mike McIntyre" <mi****@dotnetshowandtell.com> wrote in message
news:ej*************@TK2MSFTNGP12.phx.gbl...
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

"Altman" <No******@SickOfSpam.com> wrote in message
news:O1**************@TK2MSFTNGP11.phx.gbl...
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

"Mike McIntyre" <mi****@dotnetshowandtell.com> wrote in message
news:es**************@TK2MSFTNGP10.phx.gbl...
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.
"Altman" <No******@SickOfSpam.com> wrote in message
news:On**************@TK2MSFTNGP15.phx.gbl...
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


"Mike McIntyre" <mi****@dotnetshowandtell.com> wrote in message
news:ug**************@TK2MSFTNGP11.phx.gbl...
> 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
>
>
> "Altman" <No******@SickOfSpam.com> wrote in message
> news:ew**************@TK2MSFTNGP10.phx.gbl...
>>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?
>>
>
>



Nov 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.