TreeView Question

G

Guest

I have a tree view that i'm populating with a lot of heiracheral data. I only
want to populate a node with children if the user expands it. However, that
presents a problem. If I do not populate it with children then the
expand/collapse bitmap does not appear.

So, my question is how do I make the expand/collapse bitmap appear without
actually adding any children nodes? Assume that I know there will be children
nodes to add if the user expands it.
 
J

Jeff Gaines

I have a tree view that i'm populating with a lot of heiracheral data. I
only
want to populate a node with children if the user expands it. However, that
presents a problem. If I do not populate it with children then the
expand/collapse bitmap does not appear.

So, my question is how do I make the expand/collapse bitmap appear without
actually adding any children nodes? Assume that I know there will be
children
nodes to add if the user expands it.

The '.NET' way is to add a dummy node and delete it in the before expand
event (when, presumably, you populate the node).

You can do it with a call to the API:

private void TVSetIcon(JFTreeNode tNode)
{
// Needed to get the correct Icon Mask and ChildCount
TVITEM TV_ITEM = new TVITEM();
TV_ITEM.hItem = tNode.Handle;
TV_ITEM.mask = tNode.Mask | (int)TVIF.TVIF_CHILDREN;
TV_ITEM.state = tNode.State;
TV_ITEM.stateMask = tNode.StateMask;
TV_ITEM.iImage = tNode.ImageIndex;
TV_ITEM.iSelectedImage = tNode.SelectedImageIndex;

// Set child count
TV_ITEM.cChildren = tNode.ChildCount;

// Set the icon with its mask(s)
JFCommon.SendMessage(this.Handle, TVM_SETITEMW, 0, ref TV_ITEM);
}

But that may be more complex than you need?
 
B

Bryan Phillips

Add a dummy node to the unexpanded nodes that have children. When the
user clicks to expand the parent node, replace the dummy node with the
real child nodes.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top