How to Change Image for the last level(Child) in Treeview in C#?
-
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
-
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
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
-
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
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
-
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
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
-
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
-
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
..'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[^]
-
..'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[^]
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
-
..'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[^]
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
-
Thank you sir, Your suggestions about TreeNode.Level and treeView1.Nodes[3].ImageIndex = 2 , will help me.
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