This is a migrated thread and some comments may be shown as answers.

Keyboard navigation

9 Answers 127 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Srinivas
Top achievements
Rank 1
Srinivas asked on 23 Sep 2009, 08:18 PM
Hi,

I am using ItemTemplate and ItemEditTemplate for my treeview and the ItemsSource is set to an observable collection. I have added SelectionChanged event for the treeview where for each treeview item selected (essentially only by Enter key or using the Mouse) it invokes a xaml page. The issue is that when I use keyboard arrow keys to navigate the tree and when it reaches the item that has any action associated then it basically executes that action. This is because of the SelectionChanged event but I would like to execute associated action only when I press Enter key on the treeview item or using the mouse to select the item.

This behavior makes very difficult to navigate the tree using the keyboard arrow keys especially when we associate SelectionChanged event and anything that you write in that method.

Can you please suggest me how to handle this? Basically I should able to navigate the tree using the keyboard keys and only when I press Enter key on any particular item it should fire an event (?).

Also, I would like to DISABLE F2 key for edit mode as I am using Context menu for the tree and only using context menu I would like to enable the edit feature. Any suggestions?

Thanks

9 Answers, 1 is accepted

Sort by
0
Valentin.Stoychev
Telerik team
answered on 24 Sep 2009, 11:54 AM
Hello Srinivas,

You have a very valid point here. Adding this functionality is in our backlog for the treeview. For the moment the only possible workaround is not to handle the SelectionChanged event, but to handle the KeyDown event and to check for the "Enter" key. You will need to handle and the MouseLeftButtonDown event to handle the mouse clicks.

As for the f2 key. We don't support disabling this shortcut. What is your scenario? Why you need to disabled it?

The workaround for this would be to set the IsEditable property to false initially and then to set it to true everytime you want to start editing from the context menu.

Greetings,
Valentin.Stoychev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Srinivas
Top achievements
Rank 1
answered on 24 Sep 2009, 07:45 PM

Hello Valentin.Stoychev,

Thanks for your suggestion, I will try with KeyDown and MouseLeftButtonDown events to replace SelectionChanged event.

The reason that I want to disable F2 key is that the TreeViewItem consists of 5 fields including the Name which is shown in the tree. When I press F2 key I can only change the Name but not other 4 fields. I have created a simple window to maintain all 5 fields for the TreeViewItem and I would like to open that window when the user wants to edit an item. I can open that window when we select "Edit" from the ContextMenu but if there is anyway to trap the F2 key to popup the same window that would be great. Also, this window calls a WCF service upon saving the changes and I am not sure how to call the service when I use F2 key.

Thanks

0
Srinivas
Top achievements
Rank 1
answered on 25 Sep 2009, 05:17 AM
Hi,

I also want to ask you one question about Drag & Drop tree view items related to same issue that I described in my previous post. If I write event on MouseLeftButtonDown then how does Drag & Drop of tree items works? When I try to drag the tree item with any action associated then don't you think the MouseLeftButtonDown event will fire and that action is executed? When I try to drag and drop the tree item having SelectionChanged event, it is actually firing that event and making Drag & Drop very difficult.

Any suggestion is greatly appreciated.

Thanks
0
Srinivas
Top achievements
Rank 1
answered on 25 Sep 2009, 07:36 AM
Hi,

Also, can you please guide me how to set the IsSelected property to false for the TreeViewItem that I selected? Please note that the treeview is populated based on an ObservableCollection<MyObject>. The SelectedItem is of type <MyObject> but I am not sure how to get to the RadTreeViewItem from this SelectedItem, in order to set the IsSelected property to false.

I try to use below code but it always gives me null

(mytree.ItemContainerGenerator.ContainerFromItem(mytree.SelectedItem)

as RadTreeViewItem).IsSelected = false;

 


Thanks
0
Valentin.Stoychev
Telerik team
answered on 26 Sep 2009, 07:15 AM
Hello Srinivas,

There is a SelectedContainer property which you can use. Do you manage to implement the logic with mouseleftbuttondown and keydown events?

Sincerely yours,
Valentin.Stoychev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Srinivas Pulipaka
Top achievements
Rank 1
answered on 29 Sep 2009, 10:20 PM

Hi,

I was able to use the SelectedContainer property and was able to access RadTreeViewItem. Thanks

I added below two events to the RadTreeView but I am not sure why these events not getting fired when I use arrow keys or enter key or even when I press MouseLeftButton. Is there any other properties that needs to be set?

 

MyRadTreeView.KeyDown +=

new KeyEventHandler(MyRadTreeView_KeyDown);

 

MyRadTreeView.MouseLeftButtonDown +=

new MouseButtonEventHandler(MyRadTreeView_MouseLeftButtonDown);

 

 

Please note that I am using an ObservableCollection and Hierarchical template to build the tree.

Do you have any working sample to achieve the result?

Thanks
Srinivas

0
Valentin.Stoychev
Telerik team
answered on 01 Oct 2009, 07:56 AM
Hi Srinivas Pulipaka,

You should use the following syntax:

 

public MainPage()

 

{

InitializeComponent();

tree1.AddHandler(

RadTreeViewItem.MouseLeftButtonDownEvent, new MouseButtonEventHandler(HandleMouseClick), true);

 

tree1.AddHandler(

RadTreeViewItem.KeyDownEvent, new KeyEventHandler(HandleKeyDown), true);

 

 

}

 

void HandleMouseClick(object sender, MouseButtonEventArgs args)

 

{

 

}

 

 

void HandleKeyDown(object sender, KeyEventArgs args)

 

{

}


Please let us know how it goes.

Regards,
Valentin.Stoychev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Srinivas Pulipaka
Top achievements
Rank 1
answered on 02 Oct 2009, 07:10 PM
Hello Valentin.Stoychev,

I tried MouseLeftButtonDownEvent as you suggested and it is firing now but it looks like I need to add additional code to expand/collapse the parent node in this event method as this event is overriding the default expand/collapse behavior of the tree for the parent nodes. Do you have any working sample using these two events plus expand/collpase the parent node on mouse left button clicked? or am I missing something here?

I really appreciate your help.

Thanks
Srinivas
0
Bobi
Telerik team
answered on 08 Oct 2009, 08:14 AM
Hello Srinivas Pulipaka,

Please find attached a sample project that shows how to handle MouseLeftButtonDownEvent.
The example  shows how to have  expand on doubleclick and handle MouseLeftButtonDownEvent at the same time.
I hope that this will be helpful. Please let us know if you have any other questions or you need some more help.

Sincerely yours,
Boryana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
TreeView
Asked by
Srinivas
Top achievements
Rank 1
Answers by
Valentin.Stoychev
Telerik team
Srinivas
Top achievements
Rank 1
Srinivas Pulipaka
Top achievements
Rank 1
Bobi
Telerik team
Share this question
or