473,325 Members | 2,442 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Indexed Property

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
6 1844
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Kor | last post by:
Hi, Am I right that indexed properties are implemented in VB ..NET, but NOT in C#. It seems that for C# you have to wrap the property in a separate class, for emulating index properties. In...
1
by: Pradeep Kumar | last post by:
I have a scenario where I am writing a property(using get and set) have to return a member of an object stored in an array of objects! The class user has to pass an index based on which a object i's ...
7
by: Ioannis Vranos | last post by:
Fellows there is probably a serious implementation bug of C++/CLI indexed property in VC++ 2005, it looks like it is implemented the opposite way than the C++/CLI draft says! At first the...
1
by: Mike | last post by:
Hi, I have created a collection of a custom class. Everything works fine (can add these items in a combo from within a VB.NET application, for instance), but when looking at the collection from a...
0
by: liko81 | last post by:
I have an Invoice class that must know, directly or indirectly, how to do anything associated with creating, reading, or otherwise processing an invoice to a customer. It is an uber-DAO object that...
1
by: solar | last post by:
Indexed.Yes (Duplicates OK). In my code for remote control i wanted to remove the property Indexed of a field, but i receive the date type conversion error.How can i change these properties by...
7
by: Tom Dacon | last post by:
I'm using Reflection to iterate over the properties and fields of an arbitrary object. For non-indexed properties it's pi.GetValue(theObject, Nothing) for VB, or pi.GetValue(theObject, null) for...
17
by: David C. Ullrich | last post by:
Having a hard time phrasing this in the form of a question... The other day I saw a thread where someone asked about overrideable properties and nobody offered the advice that properties are...
0
by: saudamini | last post by:
i am trying to deserlize XML against the class which has this an indexed property, the deserializer just skips this indexed property, it's not setting it. I remember reading somewhere XML...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.