|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Hashtable and TreeView ?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 Luqman wrote:
> I am trying to fill the treeview in VB.Net 2005 with Hashtable with the The actual error message that's causing you trouble?> following code. .. . . > DirectCast(MyNodes(dsRow("Mgr")), TreeNode).Add(dsRow("Ename")) <------- > this line giving error .. . . > Please advise what am I missing ? 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. |
|||||||||||||||||||||||