By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,041 Members | 1,056 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,041 IT Pros & Developers. It's quick & easy.

Hashtable and TreeView ?

P: n/a
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


Nov 7 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Luqman wrote:
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.
Nov 8 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.