Do you guys have a tutorial or some sort of guide on programatically setting up columns with the Ultratree? I have 70% of it figured out I just need to put it all together.
Basically, I have a set of folders that have items, just like Explorer. I want to have 2 property columns, date added and Item Type. Issue is Item Type comes from another database entierely (only used when we interface into an accounting system). Plus all the items in the folders don't exist in the same table so I build it through code. (which works very well).
If there is not tutorial, I just need a few lines of code that explains how to add a node programatically with these columns. I have created a column set, and have added three columns.
SO now, I have something like
ut.Nodes.Add(fromSQL.ID, fromSQLName)
How can I get fromSQLName into my Column Item, then reference this item so that I can populate date added and Item TYpe.
Thanks.
The Nodes.Add method returns an UltraTreeNode. You can store this and then set the values of the cells on the node.
node.Cells["Item"].Value = whateverValueIWant;
This will only work if the ColumnSet has already been applied to the tree, of course. Otherwise the node won't know what it's columns are.
That worked out but let me ask two more brief questions.
1) So I am tried to set the image , t.Cells["Item"].Appearence.Image = copyfrom.LeftImages[0];
And , it did not work, so I tried to cast LeftImages[0] to Bitmap and it gave me an error about casting to Int32. So what I figured out I guess is that LeftImages[0] is storing the Index # of the imagelist attached to that tree. So what I ended up doing was :
worknode.Cells[0].Appearance.Image = ilProject.Images[(
Int32)t.LeftImages[0]];
You may (or may not) recall a post I had about testing for what image a node had, and I was having all those issues, so now I understand what I can do to figure out what image I have by comparing the index to the imagelist.
2) If i do this:
UltraTreeNode worknode;
worknode = Tree.Nodes.Add(tn.Clone);
the above line returns an INT...vs. the object reference. Why?
Hi,
melegant said: 2) If i do this: UltraTreeNode worknode; worknode = Tree.Nodes.Add(tn.Clone); the above line returns an INT...vs. the object reference. Why?
This is pretty standard for the Add method of a collection.If you use the overload that takes some information, such as a string for the key of the node, then the method returns you the new node that was created and added to the collection.
In this case, you are not passing in any information. you are passing in a node. tn.Clone() is a method that returns a node. So you already have a reference to the node and it would not make sense for the method to pass you back the same node you passed into it. So it returns the index at which the node was added into the collection.
So you probably want to change your code to keep a reference to the cloned node.
UltraTreeNode newNode = tn.Clone();
tree.Nodes.Add(newNode);