Another Treeview Control question...

  • Thread starter Thread starter Glyn Meek
  • Start date Start date
G

Glyn Meek

I have a routine where the driving force is a relatively complex nested
treeview. The program takes actions based upon selecting an item in the
treeview. It then goes off and performs a variety of tasks, returning
eventually to the original treeview.

The user may then select another item in the treeview for processing, OR MAY
SELECT THE SAME ITEM AGAIN.
For example...

A
a1
a2
a3
B
b1
b2 etc.

If the user selects a2 and then returns, I cannot recognize that a2 has been
selected a second time until I select one of the other entries first. I
have tried a variety of actions on the treeview such as .refresh and .focus,
but cannot seem to figure out how to 'reset' the treeview so that I can
reselect the same item.

Anyone got a hot tip for a perplexed programmer?

Regards and I hope this makes sense...


Glyn Meek
 
I'm not aware of a way to make treeView to raise an event upon subsequent
clicks on already selected node short of using techinique from ApplicationEx
class in SDF - to monitor mouse events on the message pump level.

If you can live with the approach, where the node is briefly selected and
then automatically unselected again, here is the code:

private void treeView1_AfterSelect(object sender,
System.Windows.Forms.TreeViewEventArgs e)

{

if ( e.Action == TreeViewAction.ByMouse )

{

Application.DoEvents();

MessageBox.Show(e.Node.Text);

treeView1.SelectedNode = null;

treeView1.BeginUpdate();

}

else

{

treeView1.SelectedNode = null;

treeView1.EndUpdate();

}

}
 
Back
Top