Treeview events

  • Thread starter Thread starter Andrew Ducker
  • Start date Start date
A

Andrew Ducker

I have a treeview linked to a series of panels, making the correct
panel visible depending on which node is selected.

I now want to check that the user is allowed to leave the current node
they're on before letting them do so (popping up a "You have unsaved
data - save?" box).

However, there doesn't seem to be a "BeforeLeaving" event that fires
before focus changes from one node to another.

Am I missing something, or do I have to just code my way around it?

Cheers,

Andy D
 
I assume you are speaking of the Windows Forms Treeview species.
Treeview exposes a number of events, including MouseUp and MouseDown.
If you have stored the node a user is on, you can perform your test in the
MouseDown event, checking to see if they have "Mouse Downed" onto a new node,
and do your validation check and "popup" before allowing the rest of your
event handler code to execute.

Peter
 
Andrew,

Thre is no BeforeLeaving event, but there is BeforeSelect event that covers
exactly your case.

Handle this event and check SelectedNode (this is the node that currently is
selected). Do the validation and if the data haven't been saved yet, set the
event argument's property Cancel to *true* this will cancel changing the
selection and will keep the previously selected node.


HTH
Stoitcho Goutsev (100) [C# MVP]
 
Back
Top