Tag Archives: manually clicked

Find out whether a treeview item was selected by the user (and how)

Some times it is useful to know whether a selection was made from code or by an userĀ  since the AfterCheck event of a TreeView control is fired after both.

Use the code below to see how the selection was made:

private void tree1_AfterCheck(object sender, TreeViewEventArgs e)
{
   if (e.Action == TreeViewAction.ByKeyboard)
   {
      ..
   }

   if (e.Action == TreeViewAction.ByMouse)
   {
      ..
   }
}
Lastest update in May 2011, inital post in May 2011