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. How to Change Image for the last level(Child) in Treeview in C#?

How to Change Image for the last level(Child) in Treeview in C#?

Scheduled Pinned Locked Moved C#
tutorialcsharpdatabasehelpquestion
9 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.
  • A Offline
    A Offline
    aahamdan
    wrote on last edited by
    #1

    Dear Experts, I have a problem during change image for child level in each node, I have assigned an image to treeview, and I have assigned other image to selected Node, I need to assign an image for the some childs in each node. For example: Root |_Node1 |_Child1 (Need to assign image) |_Child2 (Need to assign image) |_Child3 (Need to assign image) I have populate the treeview from Database recursively. Thanks, Ahmad

    B 1 Reply Last reply
    0
    • A aahamdan

      Dear Experts, I have a problem during change image for child level in each node, I have assigned an image to treeview, and I have assigned other image to selected Node, I need to assign an image for the some childs in each node. For example: Root |_Node1 |_Child1 (Need to assign image) |_Child2 (Need to assign image) |_Child3 (Need to assign image) I have populate the treeview from Database recursively. Thanks, Ahmad

      B Offline
      B Offline
      BillWoodruff
      wrote on last edited by
      #2

      Is it the case that you don't know what nodes are in the TreeView until it is populated ... so you have to navigate the populated TreeView and assign images to nodes based on their depth (TreeNode.Level) ? Your question implies something about selecting nodes, but I am not clear what that is. If you can be more specific, I think I have some code that will be helpful (I've spent years working with the TreeView). In any case, I am pretty sure you will need to use an ImageList to hold all possible images for the nodes: do you have that already implemented ?

      « I had therefore to remove knowledge, in order to make room for belief » Immanuel Kant

      A 1 Reply Last reply
      0
      • B BillWoodruff

        Is it the case that you don't know what nodes are in the TreeView until it is populated ... so you have to navigate the populated TreeView and assign images to nodes based on their depth (TreeNode.Level) ? Your question implies something about selecting nodes, but I am not clear what that is. If you can be more specific, I think I have some code that will be helpful (I've spent years working with the TreeView). In any case, I am pretty sure you will need to use an ImageList to hold all possible images for the nodes: do you have that already implemented ?

        « I had therefore to remove knowledge, in order to make room for belief » Immanuel Kant

        A Offline
        A Offline
        aahamdan
        wrote on last edited by
        #3

        Dear , Thank for your response, Actually, what I'm going to do is: I have a tree with folder, and these Nodes, some of these nodes is played as a child use to open Forms, for Example, General Ledger |_GL Transactions |_Enter GL Transaction Enter GL Transaction: is a child that I need to change the image for it, it is not a Folder, it is a child that will be used to open a Form. For previous node, I select a Folder image for them. I hope of you receive my point. Regards, Ahmad

        B 1 Reply Last reply
        0
        • A aahamdan

          Dear , Thank for your response, Actually, what I'm going to do is: I have a tree with folder, and these Nodes, some of these nodes is played as a child use to open Forms, for Example, General Ledger |_GL Transactions |_Enter GL Transaction Enter GL Transaction: is a child that I need to change the image for it, it is not a Folder, it is a child that will be used to open a Form. For previous node, I select a Folder image for them. I hope of you receive my point. Regards, Ahmad

          B Offline
          B Offline
          BillWoodruff
          wrote on last edited by
          #4

          Sorry, Ahmed, I don't yet understand your question. The Microsoft supplied TreeView Control has two ImageList Properties: ImageList, and StateImageList. ImageList is used to specify the image shown when the TreeNode is selected, or not selected. StateImageList is used to control the image shown for the Node when shown with a CheckBox, and the CheckBox checked or unchecked. Each TreeNode in the TreeView can have its current image changed at any time by setting either the Index or Key of the ImageList assigned to the TreeView. treeView1.Nodes[3].ImageIndex = 2; // set the Image for the Node when it's not selected treeView1.Nodes[3].SelectedImageIndex = 3;; // set the Image for the Node when it's selected See the Microsoft documentation for ImageList: [^]

          « I had therefore to remove knowledge, in order to make room for belief » Immanuel Kant

          A L 2 Replies Last reply
          0
          • B BillWoodruff

            Sorry, Ahmed, I don't yet understand your question. The Microsoft supplied TreeView Control has two ImageList Properties: ImageList, and StateImageList. ImageList is used to specify the image shown when the TreeNode is selected, or not selected. StateImageList is used to control the image shown for the Node when shown with a CheckBox, and the CheckBox checked or unchecked. Each TreeNode in the TreeView can have its current image changed at any time by setting either the Index or Key of the ImageList assigned to the TreeView. treeView1.Nodes[3].ImageIndex = 2; // set the Image for the Node when it's not selected treeView1.Nodes[3].SelectedImageIndex = 3;; // set the Image for the Node when it's selected See the Microsoft documentation for ImageList: [^]

            « I had therefore to remove knowledge, in order to make room for belief » Immanuel Kant

            A Offline
            A Offline
            aahamdan
            wrote on last edited by
            #5

            Thank you sir, Your suggestions about TreeNode.Level and treeView1.Nodes[3].ImageIndex = 2 , will help me.

            B 1 Reply Last reply
            0
            • B BillWoodruff

              Sorry, Ahmed, I don't yet understand your question. The Microsoft supplied TreeView Control has two ImageList Properties: ImageList, and StateImageList. ImageList is used to specify the image shown when the TreeNode is selected, or not selected. StateImageList is used to control the image shown for the Node when shown with a CheckBox, and the CheckBox checked or unchecked. Each TreeNode in the TreeView can have its current image changed at any time by setting either the Index or Key of the ImageList assigned to the TreeView. treeView1.Nodes[3].ImageIndex = 2; // set the Image for the Node when it's not selected treeView1.Nodes[3].SelectedImageIndex = 3;; // set the Image for the Node when it's selected See the Microsoft documentation for ImageList: [^]

              « I had therefore to remove knowledge, in order to make room for belief » Immanuel Kant

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              ..'tis was downvoted, but I cannot think of any valid reason why. So, I upvoted it. If anyone thinks this is NOT a good way to answer, please do explain it to me, using small short* sentences and simple words. *edit

              Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

              B 2 Replies Last reply
              0
              • L Lost User

                ..'tis was downvoted, but I cannot think of any valid reason why. So, I upvoted it. If anyone thinks this is NOT a good way to answer, please do explain it to me, using small short* sentences and simple words. *edit

                Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

                B Offline
                B Offline
                BillWoodruff
                wrote on last edited by
                #7

                Thanks, Eddy, I appreciate your looking our for me :) cheers, Bill

                « I had therefore to remove knowledge, in order to make room for belief » Immanuel Kant

                1 Reply Last reply
                0
                • L Lost User

                  ..'tis was downvoted, but I cannot think of any valid reason why. So, I upvoted it. If anyone thinks this is NOT a good way to answer, please do explain it to me, using small short* sentences and simple words. *edit

                  Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

                  B Offline
                  B Offline
                  BillWoodruff
                  wrote on last edited by
                  #8

                  Thanks, Eddy, I appreciate your concern for "technical justice" ! cheers, Bill

                  « I had therefore to remove knowledge, in order to make room for belief » Immanuel Kant

                  1 Reply Last reply
                  0
                  • A aahamdan

                    Thank you sir, Your suggestions about TreeNode.Level and treeView1.Nodes[3].ImageIndex = 2 , will help me.

                    B Offline
                    B Offline
                    BillWoodruff
                    wrote on last edited by
                    #9

                    You can, of course, post other questions here, or in the QA forums. Keep in mind that for any TreeNode you have several possible 'dynamic visual state' factors that may determine your choice of images to be used in displaying the node: 1. has child nodes, or has no child nodes 2. if has child nodes: is expanded, or collapsed 3. is selected, or is not selected: unfortunately unless you owner-draw the TreeView you have no control over the selection highlight color, and every scheme I have seen to work-around this (using the TreeView as is: i.e., not owner-drawn) has been not useful (impaired performance, etc.). 4. the current level: this could be a dynamic factor if you are implementing drag-drop in the TreeView To assist you in determining the node's current state at run-time there are four boolean properties which are read-only: IsEditing IsExpanded IsSelected IsVisible cheers, Bill

                    « I had therefore to remove knowledge, in order to make room for belief » Immanuel Kant

                    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