VB to C# TreeView problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • balurajeev84
    New Member
    • Feb 2008
    • 3

    VB to C# TreeView problem

    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
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Anything in the System.Collecti ons namespace would be fine?
    Maybe:
    System.Collecti ons.Generic.Lis t<TreeNode>
    The functionality should be roughly the same.

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      Hi Balu,
      Welcome to theScripts!

      In order to help answer your questions more quickly please provide a meaningful Title for any threads you start (your title should reflect the problem your having).
      Check out the Posting Guidelines for a set of rules that we follow here and especially take a look at the section on Please Use Appropriate Titles for New Threads. This not only helps us to answer your question more quickly but also helps to ensure that other members, and the general public, will have a better chance of finding answers to any similar questions.

      Since you're posting in the .NET forum I also recommend you check out the stick post about how to Get a Faster Answer To Your Question for some tips on good titles in this forum.


      Thanks!

      -MODERATOR Frinny

      Comment

      • balurajeev84
        New Member
        • Feb 2008
        • 3

        #4
        Originally posted by Plater
        Anything in the System.Collecti ons namespace would be fine?
        Maybe:

        The functionality should be roughly the same.
        i cant access System.Collecti ons.Generic.Lis t<TreeNode>

        Comment

        • balurajeev84
          New Member
          • Feb 2008
          • 3

          #5
          Originally posted by Plater
          Anything in the System.Collecti ons namespace would be fine?
          Maybe:
          System.Collecti ons.Generic.Lis t<TreeNode>
          The functionality should be roughly the same.
          i didnt get System.Collecti ons.Generic.Lis t<TreeNode>

          Comment

          • Frinavale
            Recognized Expert Expert
            • Oct 2006
            • 9749

            #6
            You're code is not completely valid. You have a line on which you have 2 Dim statements (this is not valid in VB ...since VB doesn't use ";"'s there's no way for the compiler to know what the end of the statement is)

            Have you taken a look at the TreeNode Class? It has an example on how to manipulate TreeNodes in both C# and VB.NET.

            -Frinny

            Comment

            • Plater
              Recognized Expert Expert
              • Apr 2007
              • 7872

              #7
              Originally posted by balurajeev84
              i didnt get System.Collecti ons.Generic.Lis t<TreeNode>
              Are you sure you're in .NET?

              In the solution explorer, under references, there should be some namespaces listed.
              Make sure that "System" is one of them.

              Comment

              Working...