RadTreeView(WPF) - Reaching Tag Property

3 posts, 1 answers
  1. EMRE ANDIC
    EMRE ANDIC avatar
    13 posts
    Member since:
    Jan 2010

    Posted 03 May 2010 Link to this post

    Hi,
    I added items to a treeview programmatically(with two for loop) and set the tag property to a value for each of an Child item.  But there is a problem.

     

     

     

    RadTreeViewItem rti;

     

     

    for (int i = 0; i < ParentCount; i++)

     

    {

     

      rti =

    new RadTreeViewItem();

     

      rti.Header = Parent[i].Name;

     

     

      for (int j = 0; j < ChildCount; j++)

     

        {

        rti.Items.Add(Child[j].Name);

     

        rti.Tag = Child[j].Number);

     

       

    }

      MyRadTreeView.Items.Add(rti); //MyRadTreeView is declared at XAML code.

    }

    I want to reach rti's Tag property from any of an event(Selected, SelectionChange...), but none of these events give me the Tag property's value. The Tag's value comes with null. 
    How can I achieve this issue?

  2. Answer
    Valentin.Stoychev
    Admin
    Valentin.Stoychev avatar
    2198 posts

    Posted 06 May 2010 Link to this post

    Hello EMRE ANDIC,

    Here is a modified sample code:
    public Window1()
            {
                InitializeComponent();
                Loaded += new RoutedEventHandler(Window1_Loaded);
            }
      
            void Window1_Loaded(object sender, RoutedEventArgs e)
            {
                RadTreeViewItem rti;
      
                for (int i = 0; i < 5; i++)
                {
                    rti = new RadTreeViewItem();
                    rti.Header = i;
                    for (int j = 0; j < 3; j++)
                    {
                        RadTreeViewItem item = new RadTreeViewItem();
                        item.Header = j;
                        item.Tag = j;
                        rti.Items.Add(item);
                    }
      
                    RadTreeView1.Items.Add(rti); //MyRadTreeView is declared at XAML code.
                }
            }
      
            private void RadTreeView1_Selected(object sender, Telerik.Windows.RadRoutedEventArgs e)
            {
                MessageBox.Show(RadTreeView1.SelectedContainer.Tag.ToString());
            }

    The error that was in your code was that the Tag property was not assigned to the child items, but to their parent.

    Kind regards,
    Valentin.Stoychev
    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.
  3. UI for WPF is Visual Studio 2017 Ready
  4. EMRE ANDIC
    EMRE ANDIC avatar
    13 posts
    Member since:
    Jan 2010

    Posted 06 May 2010 Link to this post

    Hi Valentin.Stoychev,
    I discovered the SelectedContainer property from Telerik Forums 3 or 4 days ago. It is very usefull property. So I solved that issue.
    Thank you for your interest.

    Kind regards,
    Emre Andıç.
Back to Top