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

RadTreeView(WPF) - Reaching Tag Property

2 Answers 60 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
EMRE ANDIC
Top achievements
Rank 1
EMRE ANDIC asked on 03 May 2010, 08:28 AM
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 Answers, 1 is accepted

Sort by
0
Accepted
Valentin.Stoychev
Telerik team
answered on 06 May 2010, 06:43 AM
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.
0
EMRE ANDIC
Top achievements
Rank 1
answered on 06 May 2010, 08:03 AM
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ıç.
Tags
TreeView
Asked by
EMRE ANDIC
Top achievements
Rank 1
Answers by
Valentin.Stoychev
Telerik team
EMRE ANDIC
Top achievements
Rank 1
Share this question
or