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

controls in heirarchical data template - drag/tab behaviour

2 Answers 62 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Trevor
Top achievements
Rank 1
Trevor asked on 24 Mar 2011, 08:06 PM
Hi,

I have a tree view control and in the data template of some of the nodes I have a text box to allow editing of internal settings. This works perfectly except for in two respects,

1) if you try and select text within the text box with the mouse it starts a drag of the tree item. I would like a way to have the tree ignore the drag when the text box is the clicked on control.. If I return handled from the PreviewDragStarted event then the selection of text works correctly but I am unsure of a way to distinguish at this point where the original click occurred

2) where I have more than one textbox in a data template I would like clicking 'tab' to move me to the next textbox, not the tree control itself/next control on page. I have played with the KeyboardNavigation.TabNavigation settings but not found anything that worked..

any thoughts appreciated.

2 Answers, 1 is accepted

Sort by
0
Trevor
Top achievements
Rank 1
answered on 24 Mar 2011, 08:46 PM
Have resolved 1) with the following check in preview drag started:

            if (Keyboard.FocusedElement as TextBox != null)
                e.Handled = true;

but still need a hand with 2..
0
Petar Mladenov
Telerik team
answered on 30 Mar 2011, 09:57 AM
Hi Trevor,

If you use ItemEditTemplate the tab navigation from the first textbox to the second will work out of the box:
<Grid.Resources>
          <DataTemplate x:Key="itemEditTemplate">
              <StackPanel Orientation="Horizontal">
                  <TextBox Width="100" Text="Alpha" />
                  <Rectangle Fill="DeepSkyBlue" Width="2" />
                  <TextBox Width="100" Text="Alpha" />
              </StackPanel>      
          </DataTemplate>
      </Grid.Resources>
      <telerik:RadTreeView x:Name="treeView"
                           IsEditable="True"
                           ItemEditTemplate="{StaticResource itemEditTemplate}">            
      </telerik:RadTreeView>
If you use ItemTemplate istead of ItemEditTemplate, you will have to deal with tab navigation programatically like so:
<Grid.Resources>
        <DataTemplate x:Key="itemTemplate">
            <StackPanel Orientation="Horizontal">
                <TextBox Width="100" Text="Alpha" x:Name="leftBox" KeyDown="leftBox_KeyDown"/>
                <Rectangle Fill="DeepSkyBlue" Width="2" />
                <TextBox Width="100" Text="Alpha" x:Name="rightBox"/>
            </StackPanel>      
        </DataTemplate>
    </Grid.Resources>
    <telerik:RadTreeView x:Name="treeView" ItemTemplate="{StaticResource itemTemplate}" />
private void leftBox_KeyDown(object sender, KeyEventArgs e)
      {
          if (e.Key == Key.Tab)
          {
              ((sender as TextBox).Parent as StackPanel).ChildrenOfType<TextBox>()[1].Focus();
              e.Handled = true;
          }
      }
Feel free to ask if you need further assistance.

Best wishes,
Petar Mladenov
the Telerik team
Tags
TreeView
Asked by
Trevor
Top achievements
Rank 1
Answers by
Trevor
Top achievements
Rank 1
Petar Mladenov
Telerik team
Share this question
or