"Cor Ligthert" <no************@planet.nl> wrote (in
microsoft.public.dotnet.languages.vb):
Michael.
Do you want to know what you are doing wrong in the code you did not
show?
You see the code before you, how you think anybody can help you when
he does not know what you did. Therefore when you want help, show some
code (piece by piece the first time and first pasted in a noteback an
copied back in your message to make it readable)
Cor
Cor,
My, what a tactful guy you are.
Here is part of the collection of my custom object:
------------
Public Class FormLabels
Inherits System.Collections.Specialized.NameObjectCollectio nBase
Default Public ReadOnly Property Item(ByVal index As Integer) As
FormLabel
Get
Return BaseGet(index)
End Get
End Property
Default Public ReadOnly Property Item(ByVal FormCode As String) As
FormLabel
Get
Return BaseGet(FormCode)
End Get
End Property
....
End Class
---------
Here is the code where I try to iterate the collection:
---------
Protected Sub RefreshForms()
With lstForms.Items
.Clear()
Dim fl As FormLabel
Dim fls As FormLabels
fls = m_JobLabel.FormLabels 'pass the copy one time
For Each fl In fls
.Add(fl.FormCode + " (" + fl.FormNumber.ToString + ")")
Next
End With
End Sub
------------
As it stands, I get an InvalidCastException at the "For Each" statement.
I went back and changed fl's definition to "Object" and discovered that
it was handed a String (it is the element's key), not a FormLabel object.
What I don't get is what the "Each" clause goes and gets. I assumed it
was the default property, which should return an object to me, not a
string.
I can work around this by iterating the collection manually, but I want
to know how to get the "Each" to work.
-Michael