Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Customizing Tree Node

Customizing Tree Node

Scheduled Pinned Locked Moved C#
questiondata-structures
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gubber
    wrote on last edited by
    #1

    I'm building an application and I'm trying to use my own class which adds a bit extra information to a TreeNode. But even though I override ToString() when they are rendered by the TreeView they seem to use the standard TreeNode.ToString(). I'm guessing this is because when the TreeView iterates the Nodes it contains it treats them as TreeNodes. That would make sense. So the question is what is there a way to override TreeNode.ToString() or get the TreeView to treat the objects as MyTreeNodes rather than ordinary ones.

    M N G 3 Replies Last reply
    0
    • G gubber

      I'm building an application and I'm trying to use my own class which adds a bit extra information to a TreeNode. But even though I override ToString() when they are rendered by the TreeView they seem to use the standard TreeNode.ToString(). I'm guessing this is because when the TreeView iterates the Nodes it contains it treats them as TreeNodes. That would make sense. So the question is what is there a way to override TreeNode.ToString() or get the TreeView to treat the objects as MyTreeNodes rather than ordinary ones.

      M Offline
      M Offline
      mav northwind
      wrote on last edited by
      #2

      Hi! I guess you'd have to override the Text property of TreeNode, not the ToString() method. Regards, mav -- Black holes are the places where god divided by 0...

      1 Reply Last reply
      0
      • G gubber

        I'm building an application and I'm trying to use my own class which adds a bit extra information to a TreeNode. But even though I override ToString() when they are rendered by the TreeView they seem to use the standard TreeNode.ToString(). I'm guessing this is because when the TreeView iterates the Nodes it contains it treats them as TreeNodes. That would make sense. So the question is what is there a way to override TreeNode.ToString() or get the TreeView to treat the objects as MyTreeNodes rather than ordinary ones.

        N Offline
        N Offline
        Nicholas Butler
        wrote on last edited by
        #3

        Hi, Mav is right - you need the Text property, but it is not declared as virtual so you cannot override it. The displayed text can be set by using one of the constructors that takes a string, or you can set the value of the Text property directly. The TreeView just displays this value. ---------------------------- Be excellent to each other :)

        1 Reply Last reply
        0
        • G gubber

          I'm building an application and I'm trying to use my own class which adds a bit extra information to a TreeNode. But even though I override ToString() when they are rendered by the TreeView they seem to use the standard TreeNode.ToString(). I'm guessing this is because when the TreeView iterates the Nodes it contains it treats them as TreeNodes. That would make sense. So the question is what is there a way to override TreeNode.ToString() or get the TreeView to treat the objects as MyTreeNodes rather than ordinary ones.

          G Offline
          G Offline
          gubber
          wrote on last edited by
          #4

          Thanks guys... Because i need my text to be somewhat dynamic I have done a RefreshText() method which will update the Nodes Text property to what it needs to be. I hoped there was a more elegant solution but it appears not. Just means if I add a node I have to go down the tree and refresh all the nodes.. It seems to work. Thanks for your help I'm still trying to get my head around virtual override new and derivation of classes and stuff.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups