UnFiRe
asked on
Disordered Hashtable
I have a function that returns a hashtable
Public Function getProperties(ByVal itemNo As String) As Hashtable
Dim hash As New Hashtable
hash.Add("itemNo", itemNo)
hash.Add("imgSize", imgBox.Width & "x" & imgBox.Height & "px")
hash.Add("color", product.Colour)
hash.Add("shade", product.Shade)
Return hash
End Function
Then i add the keys and values to listbox items:
Dim enumer As IDictionaryEnumerator = properties.GetEnumerator
While enumer.MoveNext
If enumer.Key = "itemNo" Then
lstBox.Items.Add(enumer.Va lue)
Else
lstBox.Items.Add(enumer.Ke y & ": " & enumer.Value)
End If
End While
For some reason i endup having listbox items going in a weird order:
Shade
Color
ItemNo
imgSize
Why would that happen???
I even quickwatched the hash in the Return Hash string and the order was weird
imgSize
itemNo
Shade
Color
When i use enumerator, the order gets even more screwed up ...
Public Function getProperties(ByVal itemNo As String) As Hashtable
Dim hash As New Hashtable
hash.Add("itemNo", itemNo)
hash.Add("imgSize", imgBox.Width & "x" & imgBox.Height & "px")
hash.Add("color", product.Colour)
hash.Add("shade", product.Shade)
Return hash
End Function
Then i add the keys and values to listbox items:
Dim enumer As IDictionaryEnumerator = properties.GetEnumerator
While enumer.MoveNext
If enumer.Key = "itemNo" Then
lstBox.Items.Add(enumer.Va
Else
lstBox.Items.Add(enumer.Ke
End If
End While
For some reason i endup having listbox items going in a weird order:
Shade
Color
ItemNo
imgSize
Why would that happen???
I even quickwatched the hash in the Return Hash string and the order was weird
imgSize
itemNo
Shade
Color
When i use enumerator, the order gets even more screwed up ...
At a guess.. if these items are coming out as a different order to what you added them i.e. itemNo, imgSize, color then shade... it means they're probably being sorted by Value rather than Key... which order do you want them sorted by? Key I take it?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I add them in exact same order as i show it in the code. So, i suppose, they should be read in exact same order by the enumerator?
And if it is not so, if the keys are sorted somehow by the key, the sorting does not make sence to me.
Shade > Color > ItemNo > imgSize ? (these are the keys)
Idle_Mind, what is meant by hash code of the key?
And if it is not so, if the keys are sorted somehow by the key, the sorting does not make sence to me.
Shade > Color > ItemNo > imgSize ? (these are the keys)
Idle_Mind, what is meant by hash code of the key?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>> Idle_Mind, what is meant by hash code of the key?
Some understandable discussion on the topic here:
http://searchdatabase.techtarget.com/sDefinition/0,,sid13_gci212230,00.html
Some understandable discussion on the topic here:
http://searchdatabase.techtarget.com/sDefinition/0,,sid13_gci212230,00.html
ASKER
Thank you very much guys!
Very informative
Very informative