a better TreeNode class... tell me what you think

E

Eric Newton

I'm working on a project with a couple of TreeView controls and I've
realized that once you desire true node-context-menus that its incredibly
difficult to achieve...

For instance, I first tried to tie into the AfterSelect event, which has a
reference to the newly selected node as part of the Event args passed in,
however... its actually too LATE for a context menu to be displayed!

So, I began to think about "how would I want treenodes to be" and I came up
with this:

A) TreeNodeEx, inheriting from TreeNode [System.Windows.Forms namespace], so
that you can add these TreeNodeEx instances to a normal TreeView
B) the TreeNode itself has a ContextMenu property that will be displayed
when the TreeView gets a right mouse click and the node"EX" has ContextMenu
set... [Anybody have a suggestion on how to specify that maybe the
contextmenu should show up via Left mouse instead of the normal right
click?]
C) the TreeNode has BeforeExpand event delegates, which gives you the
ability to make the node "seem" like it has some children, but no processing
for the children takes place until the node itself is expanded... reason for
this is so that a process that might be expensive can be deferred to when
the Node itself wants to be expanded... a great example of this is the
Windows Explorer Folder treeview... each subfolder node's children arent
actually created until you expand the parent's node... saves a lot of time
having to traverse deep directory trees that you most likely dont even care
about...

Anyhow, I'll be posting progress on my website soon [its being moved to a
different hosting location]
 
K

Kalpesh Shah

I dont know, whether I understood your question correctly :-|
Still, let me try. You want a context menu to appear next to treenode & on the left click (not the usual right click)

So, remove the context menu of a treeview (keep it null)
In the mouse down event of treeview,

if (e.Button == MouseButtons.Left)
contextMenu1.Show(treeView1, new Point(e.X , e.Y));

Is this what you wanted ?

Kalpesh
 
E

Eric Newton

well, its more comprehensive then that,

i'm trying the nodes to be a little more useful instead of just being
placeholders for text in a treeview.

since the treenodes themselves are usually hierarchally arranged and are
typically more expressive then common listview items or combobox items

so the intention is to provide a richer functionality per node, hence
TreeNodeEx

its currently got a BeforeExpand event that can be used to build the notion
of more nodes when the actual process can be somewhat expensive.



--
Eric Newton
(e-mail address removed) (Remove the CC)
www.ensoft-software.com
C#/ASP.net Solutions developer

Kalpesh Shah said:
I dont know, whether I understood your question correctly :-|
Still, let me try. You want a context menu to appear next to treenode & on
the left click (not the usual right click)
 

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