Thanks for the response, Bob. I actually am using the hash table to
store key/value pairs. I was trying to add just the values to my
treeview.
The code you gave me below creates an error message:
SystemNullReferenceException
Additional Info: Object reference not set to an instance of an object
Any ideas what is going on?
--------------
Brian,
A Hashtable is for accessing members via a key. I've never used a
Hashtable
in this way before; if you simply want to store a list of objects to
retreive, an ArrayList is much more lightweight.
Having said that -- assuming those really are strings you've stored into
the
Hashtable prior to this -- along the lines of
myItem.DataFields.Add(somekey,"Foo") -- then you should be able to
retreive
them like so:
foreach (DictionaryEntry de in myItem.DataFields) {
treeView1.SelectedNode.Nodes.Add((string)de.Value) ;
}
You might see if that works ...
--Bob
"Brian" <br*********@ky.gov> wrote in message
news:63**************************@posting.google.c om...
I'm reasonably new to C#, and using a class containing a hashtable
collection to feed a treeview. My problem is that I can't pull the
data from the hashtable!
Here's the code I have:
if (myItem.DataFields.Count != 0)
foreach (string name in myItem.DataFields.Values) {
treeView1.SelectedNode.Nodes.Add (name); // Error on this line
}
myItem is an instance of my class, DataFields is the hashtable, and
you can see I'm trying to access the column containing values. I get
a 'System.NullReferenceException' at runtime.
Can someone help? Am I approaching this whole thing wrong?
Thanks,
Brian
*** Sent via Developersdex
http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!