TheBugSlayer
Programmer
I have something like this in my code:
Am I accessing the dictionary elements the wrong way? When I try to access the alGPMSPractices member in another method, the same exception is raised as it becomes empty.
If I don't do d.Clear() then the dictionary complains that the key already exists.
Any help is appreciated.
Code:
...
Private alGPMSPractices As New ArrayList
...
Do
'Load the ListView with DataReader rows
For intlvColumnIndex = 0 To lvGPMSPractices.Columns.Count - 1
intColumnOrdinal = dr.GetOrdinal(lvGPMSPractices.Columns.Item(intlvColumnIndex).Tag)
'Add a future listview column's value
strSubItems(intlvColumnIndex) = _
IIf(IsDBNull(dr.Item(intColumnOrdinal)), String.Empty, dr.Item(intColumnOrdinal))
'Add to the the dictionary
[COLOR=red]d.Add(lvGPMSPractices.Columns.Item(intlvColumnIndex).Tag, strSubItems(intlvColumnIndex))[/color]
Next
lvItem = New ListViewItem(strSubItems)
lvGPMSPractices.Items.Add(lvItem)
[COLOR=red]
alGPMSPractices.Add(d)
d.Clear()
[/color]
Loop While dr.Read()
[\code]
The practices (d Dictionary object) are added to the array list. But once d.Clear() executes, they go away, then when control enters d.Read() loop again, the next one is added and they all show. However, I get an exception stating key does not exist when I try to retrieve a value as in:
[code]
alGPMSPractices.Item(0).Item("Practice_Code")
...
Dim dic As Dictionary(Of String, String)
dic = alGPMSPractices.Item(0).Item("Practice_Description")
Am I accessing the dictionary elements the wrong way? When I try to access the alGPMSPractices member in another method, the same exception is raised as it becomes empty.
If I don't do d.Clear() then the dictionary complains that the key already exists.
Any help is appreciated.