Hashtable and TreeView ?

L

Luqman

I am trying to fill the treeview in VB.Net 2005 with Hashtable with the
following code.

my field(0)=emp id
my filed(1)=emp name
my field(2)=manager id
Dim MyNodes As New Hashtable()

Dim node As New TreeNode

Dim dsRow as Datarow

For Each dsRow In ds1.Tables(0).Rows

If IsDBNull(dsRow("MgrID")) Then

Me.TreeView1.Nodes.Add(dsRow("EmpName"))

mynodes.add(dsrow("EmpID"),dsrow("EmpName"))


Else

DirectCast(MyNodes(dsRow("Mgr")), TreeNode).Add(dsRow("Ename")) <-------
this line giving error

End If

Next



Please advise what am I missing ?

Best Regards,

Luqman
 
P

Phill W.

Luqman said:
I am trying to fill the treeview in VB.Net 2005 with Hashtable with the
following code. .. . .
DirectCast(MyNodes(dsRow("Mgr")), TreeNode).Add(dsRow("Ename")) <-------
this line giving error .. . .
Please advise what am I missing ?

The actual error message that's causing you trouble?

I'm /guessing/ it's something like this :

1) MyNodes does not contain the required Manager (it's a little unclear
whether you key these by Mgr or MgrId, but anyway), so

MyNodes( dsRow.Item("Mgr").ToString() )

is returning a Null Reference and calling [null].Add doesn;t work very
well.


Question: Do you /really/ need to load the entire tree in one go?

Personally, I would load just the /Managers/ at the root level and then,
as the user expands each of these, go and retrieve the employee list for
/just/ that manager. It's unlikely that any one user will need to see
/everyone/ all in one go.

HTH,
Phill W.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top