user414967
user414967

Reputation: 5325

treeviewer does not deselect the tree item

I wanted to create dynamic tree struture in my application. There my requirement is When the user selects any tree node and click insert the child should be inserted below the selected parent. That is working fine. Now the problem is i am unable to deselect the currently selected tree item in order to change tree item . I clicked the background of the view and tried to insert a new tree item, but still it goes to the previously selected tree node as still it highlight as the selected one. How to solve this issue?

Upvotes: 2

Views: 1429

Answers (1)

greg-449
greg-449

Reputation: 111217

If you create a TreeViewer with style SWT.SINGLE then the tree will insist on keeping an item selected unless you explicitly clear the selection.

To clear a selection use:

treeViewer.setSelection(StructuredSelection.EMPTY);

If you use SWT.MULTI as the tree style you can clear the selection with Ctrl+Click

Upvotes: 3

Related Questions