c# treeview nodes in winform repeat updates - treeview

Per the screenshots the price 84.6 repeats itself on the winform, but the underlying treeview has exactly the right nodes (only one)
There is not an explicit binding, just play around with updating nodes. What is going on?
The code is just simple TreeNode tn = new TreeNode(); and add some numbers, etc.
The updates to the code are just not getting into the display, but there's no specific binding.

To solve this I had to first of all convert the nodes to a List<TreeNode>
List<TreeNode> tnl = historyTree.TopNode.Nodes.Cast<TreeNode>().ToList();
Then after organising the nodes as required I had to clear the treeview of all nodes and add in the list of nodes
historyTree.BeginUpdate();
historyTree.TopNode.Text = q.Name;
historyTree.TopNode.Nodes.Clear();
historyTree.TopNode.Nodes.AddRange(tnl.ToArray());
historyTree.EndUpdate();

Related

Keeping currently selected node at top of treeview

I have a treeview (TVWDB) which has several node, children and grandchildren. Depending on the user these can be shown as just the parent node, or with the children or even grandchildren displayed.
The user steps through this using a button which advances down the tree at the level they have selected (ie if a child is selected then it will step through each child).
Im looking for a way that when the selected item drops down that node is shown at the top of the tree (if there are parents then it should actually be the parent node which is shown.
I keep looking at .Ensurevisible and Getvisible count but this seems to work on the 1st attempt but then start jumping around on each subsequent advance.

Cutting and pasting nodes in a TreeView control?

I'm looking to implement a cut and paste method to replace drag and drop in a TreeView control. Drag and drop no longer works in the TreeView, and I believe cut and paste will be easier for the people using it. In this TreeView, I will be working with cutting only the child nodes. This object has only parent and child nodes (parent being dates and child nodes being purchase orders.) I'm not sure if there is a cut property and/or paste property to use with treeview1.node.selected or whatever I need to use.
... upon clicking cut it copies the selected node to copynode. then remove the selected node.
so the node is stored in the copynode slot
This won't work as copynode is a reference to the thing you just removed (destroyed) so after removal copynode will point to Nothing.
Instead; when a cut event occurs store the key features of the cut node (text, key, icon index etc.) in to a module level user defined type (or delimited string/class/series of variables) and remove the node. You can then use this data as the basis to construct a new node when a paste event is raised.
(The cut/paste events are not bound to the windows clipboard, rather thay are your own inventions based upon a context menu/detection of ctrl+X/V)
im not sure how to check if the node has children when im pasting to it
if tv.SelectedItem.Children > 0 then
... got child nodes

p:tree ajax loading nodes does not display the expand icon

I'm trying to ajax load the p:tree component. The idea is to mimic the tree of a windows file system. When I click the expand icon of a node, I make a call to a service which returns list of directories under that directory node. I then simply add these new directories as child nodes of the node which was expanded. I can successfully add child nodes to a node, however, I need to see the expand icon beside every new node being added. This is not happening for me. Any child nodes I add render without the expand icon and thus I am unable to go deeper into the tree.
Furthermore, it seems that PF tree component will only display the expand icon it the node has one or more children. However, in my case, I don't know whether a node will have children or not until that node is expanded.
The source code is available at the PimeFaces forum, I am opening this question in the hopes of getting a few more eyes looking at it.
http://forum.primefaces.org/viewtopic.php?f=3&t=34819
I have managed to find a workaround for this.
Everytime I add a new node anywhere on the tree, add a 'dummy' node to it. This will ensure that every new node added will get the expand icon beside. Now, when clicking the expand icon on a node, the backing bean will remove all children and add the real nodes.
There is probably a better way of doing this so I am open to other suggestions but for the time being this will do its job.

How to create expandable listview in blackberry

i search a lot but no single link found for Expandable listview in Blackberry, i know how to create Expandable list in android ,if someone having idea about Blackberry Expandable listview than please help me.
The standard way to create List on BB is to use the ListField class. This class is extremely efficient but has a couple of drawbacks
All the rows have to be the same height
All the rows have to contiguous on the display
This makes it difficult to use this class to replicate the Android ExpandingListView.
To replicate this look on a BlackBerry device, I suggest a series of VerticalFieldManagers (VFMs). Use one for the whole list, and add to this another for each expandable item. If the item is expanded, add child list entries to the associated VFM, when not expanded, delete the child entries.
This approach will work OK up to a point - adding and removing Fields can slow down the BB device significantly if there are significant number of Fields on display. So if you have, say 20 items in the list, then it will be fine. If you have 2000, it will slow the device down significantly when you expand and contract the list (add and remove the child list items).
You can improve this performance, by making your list items (parent and child) as efficient as possible. I recommend reviewing the code that is used for the ListStyleButtonField that you will find here: http://supportforums.blackberry.com/t5/Java-Development/Implement-advanced-buttons-fields-and-managers/ta-p/488276
Update
Just wanted to clarify why ListField does not work directly, and a possible work around.
The problem with ListField is each row has a specific height. To display the child elements you really need to expand the height of the parent item to include the children, which you can't do. So you can't just update the called back paint method (called drawListRow(..) in a ListField) to achieve this look. And the other problem, is that one list item on a ListField is focused as a single entity where as I assume you would want to select the children individually.
Instead, when expanding you can add additional rows, effectively inserting the children items in the list to be drawn. You will have to add these rows with a flag, so that your drawListRow(..) method knows to paint these as children. Reverse on deletion. Note that the children items have to be the same height as everything else.
Having attempted both, I have found the VFM approach easier to manage. I would only consider the ListField approach where the list was large enough to impact performance. And when it is that large, who is going to scroll through that number of entries on their BB? If you are getting to that number, then a paging mechanism would seem more user friendly.
if you mean BlackBerry Java SDK, then take a look at TreeField class.
UPDATE:
In this case the ListField would be the most suitable choice. Implement ListFieldCallback according to your needs and attach it to the ListField instance. When user clicks on an "expandable" list item, then just process this event in ListFieldCallback and repaint your list instance. Here is the tutorial on working with ListField classes.

Blitting in the right order - a visitor problem

I'm designing a simple GUI. I have Widgets, which have children and one parent. Each Widget is a Composite object, with a vector of WidgetComposite objects. One of those WidgetComposites is a PaintingBehaviour, but the Widget doesn't know it as such.
To display my window, I use a Visitor, called the ScreenVisitor. When the Visitor is called, this is what happens :
The first widget, the WidgetScene, iterates on each of its Widgets and calls the "accept(Visitor* v)" method. Then, each widget accepts the visitor, then iterates on its children.
For instance, this is a list of the objects (in the order it's going to happen) the visitor will have to accept.
root
child1
child2
child3
child4
child5
child6
child7
Now, my problem is simple : I want each Widget to be painted on its parent. How would you proceed ? I've tried with a tree, but I always have the same problem : when I have to go up in the hierarchy (for instance, after having displayed child3, when I have to display child4) I don't know how to get the right parent.
I'm coding in C++ but this problem is not language specific.
Do you have any ideas ? Thanks in advance !
The question is not very clear to me. If you just need to get them to be painted in the correct order. Parent before children, that would be quite easy:
accept(Visitor v)
paint() //paint parent first
v.visit()
foreach child
child.accept(v) //then paint children
If you need the parent (why?), you could change the accept method to (optionally) take a parent node.
accept(Visitor v,Element parent = null)
paint()
v.visit()
parent.foo()
foreach child
child.accept(v,this)
All right, since I could not find anything else, I tried this solution :
The visitor create a tree of "DisplayNodes" objects, who are basically a class made essentially of pointers. Here are the attributes of the class :
class DisplayNode
{
private:
Widget* myWidget;
PaintingBehaviour* myPB;
DisplayNode* myParent;
vector <DisplayNode*>myChildren;
};
Every DisplayNode is stocked in a vector in my visitor.
Then, for each PaintingBehaviour, I test the parent of the Widget connected, and check if one of my Node's "myWidget" is this parent. So I can find back where is everything. After that, it's quite easy, a simple paint method in DisplayNode with recursive calls to the children, called with the first DisplayNode of the scene...
Since it's a bit heavy, I create the tree of DisplayNode only once (though I do it again if PaintingBehaviour or widgets are added / removed). If the tree already exists, I go directly to the recursive painting.
It's a bit twisted (and probably not quite optimized), I'll admit, but it works ! But if anybody has a better solution, I'll be more than happy to hear it.

Resources