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. Treeview basic question

Treeview basic question

Scheduled Pinned Locked Moved C#
question
6 Posts 4 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.
  • P Offline
    P Offline
    Priya Prk
    wrote on last edited by
    #1

    Hello, I have 2 treeviews and one button. Ofter selecting a node in the first treeview and clicking the button, the selected node most be copied into the second treeview. Bud how can i check first whether the second treeview already contains the selected node in treeview1? Thanks, Priya

    T D M 3 Replies Last reply
    0
    • P Priya Prk

      Hello, I have 2 treeviews and one button. Ofter selecting a node in the first treeview and clicking the button, the selected node most be copied into the second treeview. Bud how can i check first whether the second treeview already contains the selected node in treeview1? Thanks, Priya

      T Offline
      T Offline
      TylerBrinks
      wrote on last edited by
      #2

      Do you have a key or some kind of identifier that you're checking? Are you just checking the node text? Generally speaking, you can use recursion to check each tree node with a boolean value for whether the node exists.

      P 1 Reply Last reply
      0
      • T TylerBrinks

        Do you have a key or some kind of identifier that you're checking? Are you just checking the node text? Generally speaking, you can use recursion to check each tree node with a boolean value for whether the node exists.

        P Offline
        P Offline
        Priya Prk
        wrote on last edited by
        #3

        Just checking the node text

        T 1 Reply Last reply
        0
        • P Priya Prk

          Just checking the node text

          T Offline
          T Offline
          TylerBrinks
          wrote on last edited by
          #4

          something like this

          bool ContainsNode(string nodeText, Node treeNode){
          if(treeNode.Text.Equals(nodeText){
          return true;
          }

          bool contained = false;
          foreach(Node node in treeNode.Children){
          contained |= ContainsNode(nodeText, node);
          }

          return contained;
          }

          1 Reply Last reply
          0
          • P Priya Prk

            Hello, I have 2 treeviews and one button. Ofter selecting a node in the first treeview and clicking the button, the selected node most be copied into the second treeview. Bud how can i check first whether the second treeview already contains the selected node in treeview1? Thanks, Priya

            D Offline
            D Offline
            dan sh
            wrote on last edited by
            #5

            Create a List of the node text for second treeview. On button click, check if the list contains the text. If yes do not add. If no add the text to list and a node in treeview. This will avoid looping through nodes for each and every time. However you will have to loop through for once to create the list.

            The word "politics" describes the process so well: "Poli" in Latin meaning "many" and "tics" meaning "bloodsucking creatures." जय हिंद

            1 Reply Last reply
            0
            • P Priya Prk

              Hello, I have 2 treeviews and one button. Ofter selecting a node in the first treeview and clicking the button, the selected node most be copied into the second treeview. Bud how can i check first whether the second treeview already contains the selected node in treeview1? Thanks, Priya

              M Offline
              M Offline
              Mohammad Dayyan
              wrote on last edited by
              #6

              I often do it with LINQ. See this article http://www.codeproject.com/KB/cs/KingMark.aspx[^]

              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