Link to home
Start Free TrialLog in
Avatar of Stephan Dijkxhoorn
Stephan Dijkxhoorn

asked on

How to iterate a Dictionary(Of Integer, List(Of MyClass))

Hello  there,

I am experiencing some severe problems, when trying to iterate  a dictionary of type Dictionary(Of Integer, List (Of clsMyClass) ).

How can I access the list in a single Dictionary object ?

Public Sub TestMe()
        Dim EOL As String = vbCrLf

        Dim strText = System.IO.File.ReadAllText(_FileName)

        Dim _lines As String()
        _lines = Split(strText, EOL)

        Dim EDIFileReferences As New Dictionary(Of Integer, List(Of clsEDI_FileImportMappingClass))
		'(1)
        For row As Integer = 0 To _lines.Count - 1
            Dim line As String
            line = _lines(row)
            Dim SEGMDESC As String = Left(line, 3)
            Dim Filter As String = line.Substring(3, 2)
            Dim Mapping As List(Of clsEDI_FileImportMappingClass) = Profil.getEdiSegCols(SEGMDESC, Filter)
            Dim x As New List(Of clsEDI_FileImportMappingClass)
            x = MapContentsOfImportedEdiFile(line, Mapping)
            EDIFileReferences.Add(row, New List(Of clsEDI_FileImportMappingClass))
            EDIFileReferences(row) = x
		Next
                '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!		
		' (2) Following fragment is showing only identical contents:
                '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


        For row As Integer = 0 To EDIFileReferences.Count - 1

            Dim objList As List(Of clsEDI_FileImportMappingClass) = EDIFileReferences(row)
            Dim sout As String : sout = ""
            For x As Integer = 0 To EDIFileReferences(row).Count - 1
                sout = "ROW IN FILE: " & row.ToString & " | SEGMENT: " & EDIFileReferences(row).Item(x).SEGMENT & " | FELD-NR.:" & EDIFileReferences(row).Item(x).EDI_FIELD & " | CONTENTS: " & EDIFileReferences(row).Item(x).CONTENTS.ToString
                Debug.Print(sout)
            Next
        Next

End Sub

' *****************************************************

Public Function MapContentsOfImportedEdiFile(ByVal csvline As String, ByVal ediDBObjMapping As List(Of clsEDI_FileImportMappingClass)) As List(Of clsEDI_FileImportMappingClass)

        Dim x As New List(Of clsEDI_FileImportMappingClass)
        ' Processing ediDBObjMapping 

        ' Return mapped contents
        Return x
   End Function

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Fernando Soto
Hi Stephan;

This is how to iterate through the List stored in the Dictionary object.
Dim myDictionary As New Dictionary(Of Integer, List(Of clsMyClass))
myDictionary.Add(1, mClass)

'' Get a List of clsMyClass from the Dictionary
Dim theList As List(Of clsMyClass) = myDictionary(1)
'' Iterate through the List of clsMyClass
For Each item As clsMyClass In theList
	Console.WriteLine("Name: {0} and Age: {1}", item.Name, item.Age)
Next

Open in new window

Avatar of Stephan Dijkxhoorn
Stephan Dijkxhoorn

ASKER

I found a working solution and there was no connection to your answer, Fernando.
Hi Stephan;

The solution you selected does not even handle the case you gave in the question having a dictionary of in't list of objects we're mine does how come you selected that solution can you explain please.