Hi,
I am trying to convert a VB.net code to C# .
it is to bind a treeview from a collection. but not finding a Collection which stores treenodes as object.
Cant use hashtable since it automatically sorts the data by key.
Can anybody tell me a collection which takes objects and doesn't sort it.
The code is as follows. can anybody convert this?
[code=vbnet]
Private Sub TreeViewPopulat ion(ByVal ds As DataSet, Optional ByVal intParent As Integer = 0)
Dim TvwParent As New TreeNode
Dim TvwNode As New TreeNode Dim CollItems As New Collection
Try
tvw.Nodes.Clear ()
For Each dr As DataRow In ds.Tables(0).Ro ws ''''assigning dataset values to a collection as node
TvwNode = New TreeNode(dr("Em ployee_Nm").ToS tring)
TvwNode.Tag = dr("Parent")
CollItems.Add(T vwNode, dr("Employee_Id "))
Next
For Each TvwNode In CollItems
TvwParent = Nothing
'find parent of a node
If Val(TvwNode.Tag ) <> intParent Then TvwParent = CType(CollItems .Item(TvwNode.T ag.ToString), TreeNode)
If Not TvwParent Is Nothing Then
'add child node to its parent node
CType(CollItems .Item(TvwNode.T ag.ToString), TreeNode).Nodes .Add(TvwNode.Cl one)
Else
tvw.Nodes.Add(T vwNode) 'add node to Treeview
End If
Next
Catch ex As Exception MsgBox("TreeVie w Population Error", MsgBoxStyle.Cri tical)
End Try
End Sub
[/code]
plz dont give me the online code converter
Thanks in Advance, Balu
I am trying to convert a VB.net code to C# .
it is to bind a treeview from a collection. but not finding a Collection which stores treenodes as object.
Cant use hashtable since it automatically sorts the data by key.
Can anybody tell me a collection which takes objects and doesn't sort it.
The code is as follows. can anybody convert this?
[code=vbnet]
Private Sub TreeViewPopulat ion(ByVal ds As DataSet, Optional ByVal intParent As Integer = 0)
Dim TvwParent As New TreeNode
Dim TvwNode As New TreeNode Dim CollItems As New Collection
Try
tvw.Nodes.Clear ()
For Each dr As DataRow In ds.Tables(0).Ro ws ''''assigning dataset values to a collection as node
TvwNode = New TreeNode(dr("Em ployee_Nm").ToS tring)
TvwNode.Tag = dr("Parent")
CollItems.Add(T vwNode, dr("Employee_Id "))
Next
For Each TvwNode In CollItems
TvwParent = Nothing
'find parent of a node
If Val(TvwNode.Tag ) <> intParent Then TvwParent = CType(CollItems .Item(TvwNode.T ag.ToString), TreeNode)
If Not TvwParent Is Nothing Then
'add child node to its parent node
CType(CollItems .Item(TvwNode.T ag.ToString), TreeNode).Nodes .Add(TvwNode.Cl one)
Else
tvw.Nodes.Add(T vwNode) 'add node to Treeview
End If
Next
Catch ex As Exception MsgBox("TreeVie w Population Error", MsgBoxStyle.Cri tical)
End Try
End Sub
[/code]
plz dont give me the online code converter
Thanks in Advance, Balu
Comment