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

Unable to type <space> key while editing nodes in a tree.

1 Answer 51 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Rob
Top achievements
Rank 1
Rob asked on 03 Jun 2011, 07:30 PM
Hello,

I have created a very simple RadTreeView project that builds a tree using ItemTemplateSelectors and ItemEditTemplateSelectors.  The dataset is a simple heirarchical ObservableCollection of my TreeNode object.

Whenver I am editing a non-root node, if I attempt to add a <space> it will not be typed, and the parent of the edited node will have it's selection property toggled.  Am I doing something incorrectly here or is this a bug I've discovered?  If I try to add a <space> to the root node, it works fine.

My code is as follows (sorry I can't attach a project here):
<telerik:RadTreeView   x:Name="rtv"
                                        IsEditable="True"
                                        ItemsSource="{Binding}"
                                        ItemTemplateSelector="{StaticResource tnits}"
                                        ItemEditTemplate="{x:Null}"
                                        ItemEditTemplateSelector="{StaticResource tneits}">
</telerik:RadTreeView>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using Telerik.Windows.Controls;
  
namespace SilverlightApplication50
{
    public partial class MainPage : UserControl
    {
  
        ObservableCollection<TreeNode> root = new ObservableCollection<TreeNode>();
  
        public MainPage()
        {
            InitializeComponent();
  
            TreeNode r = new TreeNode(0, 0, "r");
  
            TreeNode a = new TreeNode(1000, 1, "a");
            a.AddChild(new TreeNode(1001, 2, "a1"));
            a.AddChild(new TreeNode(1002, 2, "a2"));
            a.AddChild(new TreeNode(1003, 2, "a3"));
            a.AddChild(new TreeNode(1004, 2, "a4"));
            a.AddChild(new TreeNode(1005, 2, "a5"));
            a.AddChild(new TreeNode(1006, 2, "a6"));
            a.AddChild(new TreeNode(1007, 2, "a7"));
            a.AddChild(new TreeNode(1008, 2, "a8"));
            a.AddChild(new TreeNode(1009, 2, "a9"));
            a.AddChild(new TreeNode(1010, 2, "a10"));
            a.AddChild(new TreeNode(1011, 2, "a11"));
            a.AddChild(new TreeNode(1012, 2, "a12"));
  
            TreeNode b = new TreeNode(2000, 1, "b");
            b.AddChild(new TreeNode(2001, 2, "b1"));
            b.AddChild(new TreeNode(2002, 2, "b2"));
            b.AddChild(new TreeNode(2003, 2, "b3"));
            b.AddChild(new TreeNode(2004, 2, "b4"));
            b.AddChild(new TreeNode(2005, 2, "b5"));
            b.AddChild(new TreeNode(2006, 2, "b6"));
            b.AddChild(new TreeNode(2007, 2, "b7"));
            b.AddChild(new TreeNode(2008, 2, "b8"));
            b.AddChild(new TreeNode(2009, 2, "b9"));
            b.AddChild(new TreeNode(2010, 2, "b10"));
            b.AddChild(new TreeNode(2011, 2, "b11"));
            b.AddChild(new TreeNode(2012, 2, "b12"));
  
            r.AddChild(a);
            r.AddChild(b);
  
            root.Add(r);
  
            this.DataContext = root;
  
        }
      
    }
          
}

public class TreeNodeItemTemplateSelector : DataTemplateSelector
    {
  
        public HierarchicalDataTemplate hdt_Level0
        {
            get
            {
                return Application.Current.Resources["hdt_Level0"] as HierarchicalDataTemplate;
            }
        }
  
        public HierarchicalDataTemplate hdt_NotLevel0
        {
            get
            {
                return Application.Current.Resources["hdt_NotLevel0"] as HierarchicalDataTemplate;
            }
        }
  
        public TreeNodeItemTemplateSelector()
        {
        }
  
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
  
            base.SelectTemplate(item, container);
  
            TreeNode tn = item as TreeNode;
  
            if (tn.Level == 0)
            {
                return this.hdt_Level0;
            }
  
            else
            {
                return this.hdt_NotLevel0;
            }
  
        }
  
    }
  
  
  
    public class TreeNodeItemEditTemplateSelector : DataTemplateSelector
    {
  
        public DataTemplate dt_Level0_Edit
        {
            get
            {
                return Application.Current.Resources["dt_Level0_Edit"] as DataTemplate;
            }
        }
  
        public DataTemplate dt_NotLevel0_Edit
        {
            get
            {
                return Application.Current.Resources["dt_NotLevel0_Edit"] as DataTemplate;
            }
        }
  
        public TreeNodeItemEditTemplateSelector()
        {
        }
  
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
  
            base.SelectTemplate(item, container);
  
            TreeNode tn = item as TreeNode;
  
            if (tn.Level == 0)
            {
                return this.dt_Level0_Edit;
            }
  
            else
            {
                return this.dt_NotLevel0_Edit;
            }
  
        }
  
    }

<Application.Resources>
  
        <local:TreeNodeItemTemplateSelector x:Key="tnits"/>
          
        <telerik:HierarchicalDataTemplate x:Key="hdt_Level0" ItemTemplateSelector="{StaticResource tnits}" ItemsSource="{Binding Children}">
            <TextBlock Text="{Binding Name}" Foreground="Red" />
        </telerik:HierarchicalDataTemplate>
  
        <telerik:HierarchicalDataTemplate x:Key="hdt_NotLevel0" ItemTemplateSelector="{StaticResource tnits}" ItemsSource="{Binding Children}">
            <TextBlock Text="{Binding Name}" Foreground="Blue" />
        </telerik:HierarchicalDataTemplate>
  
  
  
  
        <local:TreeNodeItemEditTemplateSelector x:Key="tneits" />
        <DataTemplate x:Key="dt_Level0_Edit">
            <Grid>
                <StackPanel Orientation="Horizontal">
                    <TextBox Text="{Binding Name, Mode=TwoWay}" Foreground="DarkSalmon" />
                    <TextBox Text="{Binding ID, Mode=TwoWay}" Foreground="LemonChiffon" />
                </StackPanel>
            </Grid>
        </DataTemplate>
  
        <DataTemplate x:Key="dt_NotLevel0_Edit">
            <Grid>
                <StackPanel Orientation="Vertical" Background="Pink">
                    <TextBox Text="{Binding Name, Mode=TwoWay}" Foreground="BlueViolet" />
                    <TextBox Text="{Binding ID, Mode=TwoWay}" Foreground="DarkMagenta" />
                </StackPanel>
            </Grid>
        </DataTemplate>
  
  
    </Application.Resources>

public class TreeNode : INotifyPropertyChanged
    {
  
        private int _ID = 0;
        public int ID
        {
            get
            {
                return this._ID;
            }
            set
            {
                this._ID = value;
                RaisePropertyChanged("ID");
            }
        }
  
        private int _Level = 0;
        public int Level
        {
            get
            {
                return this._Level;
            }
            set
            {
                this._Level = value;
                RaisePropertyChanged("Level");
            }
        }
  
        private string _Name = "[New]";
        public string Name
        {
            get
            {
                return this._Name;
            }
            set
            {
                this._Name = value;
                RaisePropertyChanged("Name");
            }
        }
  
        private ObservableCollection<TreeNode> _Children = new ObservableCollection<TreeNode>();
        public ObservableCollection<TreeNode> Children
        {
            get
            {
                return this._Children;
            }
            set
            {
                this.Children = value;
                RaisePropertyChanged("Children");
            }
        }
  
        public TreeNode(int id, int level, string name)
        {
            this.ID = id;
            this.Level = level;
            this.Name = name;
        }
  
        public void AddChild(TreeNode tn)
        {
            this.Children.Add(tn);
            RaisePropertyChanged("Children");
        }
  
        public void RemoveChild(TreeNode tn)
        {
            if (this.Children.Contains(tn))
            {
                this.Children.Remove(tn);
            }
            RaisePropertyChanged("Children");
        }
          
        public event PropertyChangedEventHandler PropertyChanged;
  
        protected void RaisePropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
            if ((propertyChanged != null))
            {
                propertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
  
  
    }






1 Answer, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 06 Jun 2011, 05:05 PM
Hello Rob,

This was known issue in the RadTreeView from Q1 2011 (0315). The good news is that this was fixed a few weeks after the official release and you can use the official Q1 2011 SP1 (0419). Please accept our apologies for any inconvenience caused.

Regards,
Petar Mladenov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
TreeView
Asked by
Rob
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Share this question
or