0

I have an application that uses treeview in wpf with mvvm. The treeitem template contains a textbox for the user to enter or change field data. I would like if the user presses tabwhile editing if it would move to the next visible treeitem textbox and allow them to start editing that. Is this possible? I can catch the tab key but can't figure out how to move to the next item

sfaust
  • 2,089
  • 28
  • 54

1 Answers1

0

Ok I'm not sure it's the cleanest way but I found a way to do it and it doesn't seem to be suffering from speed issues so it works for now, still would be interested in a cleaner answer if anyone has one. Here is what I did:

I used a method similar to the one referenced here to get a collection of all the textboxes in the TreeView. I then used 'sender' for the KeyDown event, cast to a textbox, and got it's datacontext which is my view model for that node. I then used my overall viewmodel to find the view model of the next visible node (very easy with a two way binding to 'IsExpanded'). Last, I iterated over all of the textboxes found at the start until I found one who's datacontext was the next visible view model and called Keyboard.Focus(myTextBox) on it.

Like I said, it seems like there should be a cleaner way but it works for now...

Community
  • 1
  • 1
sfaust
  • 2,089
  • 28
  • 54