Using visual studios 2010 and c# i have a treeview and i added images to each of the nodes. In retrospect i now want to remove the images that are associated with the children of the 3 main root nodes. How do i remove the images from the children of my 3 main root nodes but keep the images on the 3 root nodes?
I have tried opening the properties for the nodes and changed the ImageIndex and SelectedImageIndex to "none" for all of the children nodes and when i press ok, it still shows the default image for each child node.
Thanks
I'm not sure of it, but I believe that you can pass through every control inside the TreeView doing a foreach in [TreeView].Controls... In there you can search for [control].GetType() == typeof([type_of_the_image]), and do some logic to get just the main ones.
Besides that, you can remove by jQuery, doing something close to what I said above. If these ideas are something that interests you, I can help with the development.
Related
I am new to using Windows forms and am looking for help on creating a Tree Node Menu Structure in Windows Forms. I have tried reading the documentation on Microsoft docs and testing out the examples still with no clear understanding of how to create a tree node menu structure. Any help would be greatly appreciated as I am just learning Windows Forms.
Here is an example of how I would like the structure (the menu items should be tabs):
Node: Customers
-Child node: Add Customers
-Child Node: Add Customer Part
Not 100% sure if this is what you are looking for, but basically define your context menu (assuming a right click here)
nodeMenu As ContextMenuStrip
Build your items and a menu handler, then when your node is selected, define which items of the menu will be available along these lines:
if node.Text.Equals("Customers") then
nodeMenu.Items("Add Customers").Enabled = True
nodeMenu.Items("Add Customer Part").Enabled = True
Else
'do something else
End If
but that is to add a menu to a node.
I think what you want is add nodes under a specfic node, if that is the case, I believe what you are after is more likely the answer here:
https://stackoverflow.com/a/9963900/1946036
Consider a large TreeView; some nodes and subnodes are expanded others are collapsed. The user adds a child node to a node and the program saves everything back to the underlying XML file. Then the TreeView rebuilds. The problem is that only the root node is expanded; all other nodes are collapsed.
Has anybody ever seen code (I don't think there's anything built into WPF that does this) that saves the state of the TreeView (which nodes are expanded) and then is able to restore it to this state after a save?
Any ideas?
Edit
Well, that link didn't really help. I'm thinking of creating an array and storing the state of isExpanded and then reading it back after the load.
One has to manage the treeview's states directly and note when a node is expanded or collapsed. Then on load or refresh, open / close the nodes as needed.
I am using the following Infragistics component for viewing hierarchical data.
http://www.igniteui.com/tree/drag-and-drop-single-tree
I could able to load data correct but the problem is wI cant expand multiple nodes simultaneously. I mean when I expand a node the other node collapsed expanding only the current node. Can some one please suggest if there is any configuration setting I am missing to accomplish this?
I want the nodes once expanded will remain expanded until user collapses it again.
Thanks,
Krishna Prasad
The option that controls that is singleBranchExpand. Set it to false to allow multiple nodes to be expanded at the same time. http://jsfiddle.net/ywtLL7ka/
$("#tree").igTree({
singleBranchExpand: false,
});
I am working on a windows form application, where I connect to the database and get a list of projects and sub-projects. I am able to show this as a treeview with checkboxes, that later an user can select to do further operations.
My problem is that, I can't set the Parent node state when one of the child nodes is selected. Here, I want some indication, if any of the child nodes is selected the parent node should fill in to show that something has been selected below that parent node.
Okay, meanwhile, I found answer to my problem. Not really wise but thanks to this Simple Tri-State TreeView control. code link here.
I will definitely try to build my own custom version of this. For now, this works fine.
I currently have a simple tree view that contains one parent node with multiple child nodes. I was wondering if there is a way to find the location of the selected node in the parent tree.
I currently have an action event on the treeview and when the user clicks on the child it prints out the string value of the selected child. I have tried using:
int val = TreeView.SelectedItemProperty.GlobalIndex;
but it always returns 0. I have seen some examples in VB but I cant seem to get the same idea to work in C#.
You have to use the ItemContainerGenerator property of the Treeview.
http://msdn.microsoft.com/en-us/library/system.windows.controls.itemcontainergenerator.aspx
See: ContainerFromIndex and IndexFromContainer
Note that each TreeViewItem also has an ItemContainerGenerator (its an ItemsControl), so you'd have to recursively search down the tree if you have multiple levels.
I think the answer to all your treeview problems (and most ui ones) in wpf is to build a ViewModel. Anytime you start crawling the visual tree to look for elements that you are already binding to, you are doing things the hard way. Once you start using ItemsContainerGenerator you have to start worrying about a whole lot of issues you should not have to.
You are binding to a hierarchical structure. If that structure has a selected item property on each item and it is bound to the TreeViewItem selected item then you can just get the selected item in code and do everything else from there. Have a look at a similiar question here.
So i didn't find the answer i was looking for (I may of confused others with what my question was. by saying location). Anyways how I solved it was I got the string value of the child selected and compared it to my list. Thanks to those who answered!