Menu

#5 Couple of additional events

open
nobody
None
5
2007-07-05
2007-07-05
Anonymous
No

Hi, Andrew,

Thans a lot for a nice control which I'm going to use in my projects. Unfortunately it's not a drop-in replacement for a standard TreeView but with a lot of added functionality one couldn't hope for this. However it seems to me that a couple of additional event would help in certain situations. Th be precise I'm thinking of:

MouseNodeClick
--------------
Ideally it should be raised after MouseDown but before MouseClick so that context menu opening could be prevented if need be. It should happen only if any of node controls is clicked (not in empty space or in some column) and event arguments should contain clicked TreeNodeAdv. TreeNodeAdvMouseEventArgs would be just fine. As a quick patch I placed it in TreeViewAdv::OnMouseDown like that

....
base.OnMouseDown(e);

if (args.Node != null)
OnNodeMouseClick(args);
....

SelectionChanging
-----------------
It should happen before selection has been changed in any way so that currently selected nodes are still valid and can be accessed. Event arguments should contain a node to be selected and contain writable Cancel property. If event handler sets this property to true, no change in selection should occur.

A poor man's replacement for this functionality looks like that:

private void treeViewAdv1_SelectionChanged(object sender, EventArgs e)
{
// To prevent recursion after setting SelectedNode
// programmatically
if (m_changingSelection) return;
m_changingSelection = true;

TreeNodeAdv newSelectedNode =
treeViewAdv1.SelectedNode;

if (newSelectedNode != null)
{
if (<dont'want to change selection>)
{
treeViewAdv1.SelectedNode = m_selectedNode;
}
else
{
m_selectedNode = newSelectedNode;
}
}
m_changingSelection = false;
}

Again thank you for a great job!

Alexander Slinkin
Moscow
estermad@mail.ru

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.