I agree that use TreeViewAction.Unknownin this case is less desirable. Consider using an event BeforeSelectthat provides an opportunity to prevent the event AfterSelect.
Create an event handler GotFocusthat sets the flag. Then create an event handler BeforeSelectthat, if the flag is set, cancels the event and clears the flag. For example:
private bool treeViewWasNewlyFocused = false;
private void TreeView1_BeforeSelect(object sender, TreeViewCancelEventArgs e)
{
if(treeViewWasNewlyFocused)
{
e.Cancel = true;
treeViewWasNewlyFocused = false;
}
}
private void TreeView1_GotFocus(object sender, EventArgs e)
{
treeViewWasNewlyFocused = true;
}
Jeff mattfield
source
share