This question is locked. New answers and comments are not allowed.
Hi
I have DataModel
Country -> List<City>
and this is shown in RadTreeView with load on demand.
I need to know at any time full path to selection in TreeView ( I call different function depending on Selectiion in Tree).
How to achive this?
If I take example from documentation : http://www.telerik.com/help/silverlight/radtreeview-how-to-get-previous-next-parent-sibling-node.html
it gives error.
I need to know at any time what is full path to selection in TreeView. How to achive this.
Sample project attached.
Pls help.
I have DataModel
Country -> List<City>
and this is shown in RadTreeView with load on demand.
I need to know at any time full path to selection in TreeView ( I call different function depending on Selectiion in Tree).
How to achive this?
If I take example from documentation : http://www.telerik.com/help/silverlight/radtreeview-how-to-get-previous-next-parent-sibling-node.html
it gives error.
I need to know at any time what is full path to selection in TreeView. How to achive this.
Sample project attached.
Pls help.
<DataTemplate x:Key="PopulationTemplate"> <StackPanel Orientation="Horizontal"> <TextBlock Text="{Binding Name}"/> <TextBlock Text=": "/> <TextBlock Text="{Binding Count}"/> </StackPanel> </DataTemplate> <telerik:HierarchicalDataTemplate x:Key="CountriesTemplate" ItemsSource="{Binding Cities}" ItemTemplate="{StaticResource PopulationTemplate}"> <TextBlock Text="{Binding Name}"/> </telerik:HierarchicalDataTemplate> </Grid.Resources> <telerik:RadTreeView ItemsSource="{Binding Countries}" IsLoadOnDemandEnabled="True" LoadOnDemand="RadTreeView_LoadOnDemand" ItemTemplate="{StaticResource CountriesTemplate}" IsLineEnabled="True" SelectedItem="{Binding SelectedItem, Mode=TwoWay}" ItemPrepared="RadTreeView_ItemPrepared" SelectionChanged="RadTreeView_SelectionChanged"/> public partial class MainPage : UserControl { Model.ViewModel vm; public MainPage() { InitializeComponent(); vm = new Model.ViewModel(); this.DataContext = vm; } private void RadTreeView_LoadOnDemand(object sender, Telerik.Windows.RadRoutedEventArgs e) { RadTreeViewItem currentItem = e.OriginalSource as RadTreeViewItem; Country country = currentItem.Item as Country; if (country != null) { vm.LoadCities(country); } City city = currentItem.Item as City; if (city != null) { currentItem.IsLoadOnDemandEnabled = false; var c = currentItem.ParentItem.Item as Country; vm.LoadExtraData(c, city); } } private void RadTreeView_ItemPrepared(object sender, RadTreeViewItemPreparedEventArgs e) { RadTreeViewItem item = e.PreparedItem as RadTreeViewItem; if (item != null && item.Item is City) { item.IsLoadOnDemandEnabled = false; } } private void RadTreeView_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangedEventArgs e) { //From dosc: http://www.telerik.com/help/silverlight/radtreeview-how-to-get-previous-next-parent-sibling-node.html // Get a reference to the treeview Telerik.Windows.Controls.RadTreeView treeView = sender as Telerik.Windows.Controls.RadTreeView; // Get the currently selected items ObservableCollection<Object> selectedItems = treeView.SelectedItems; //Here always null!!!!!!!!!!!!!!!!!!!!!!!!!!!! because selectedItem is not RadTreeViewItem - it is Country or City RadTreeViewItem item = selectedItems[0] as RadTreeViewItem; //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // Get the previous item and the previous sibling item RadTreeViewItem previousItem = item.PreviousItem; RadTreeViewItem previousSiblingItem = item.PreviousSiblingItem; // Get the next item and the next sibling item RadTreeViewItem nextItem = item.NextItem; RadTreeViewItem nextSiblingItem = item.NextSiblingItem; // Get the parent item and the root item RadTreeViewItem parentItem = item.ParentItem; RadTreeViewItem rootItem = item.RootItem; } }public class ViewModel : ModelBase { public ObservableCollection<Country> Countries { get; set; } public ViewModel() { Countries = new ObservableCollection<Country>(); LoadCountries(); } private Country _SelectedCountry; public Country SelectedCountry { get { return _SelectedCountry; } set { _SelectedCountry = value; RaisePropertyChanged("SelectedCountry"); } } private City _SelectedCity; public City SelectedCity { get { return _SelectedCity; } set { _SelectedCity = value; RaisePropertyChanged("SelectedCity"); } } private object _SelectedItem; public object SelectedItem { get { return _SelectedItem; } set { _SelectedItem = value; RaisePropertyChanged("SelectedItem"); } } public void LoadCountries() { Countries.Add(new Country() { Name = "US" }); Countries.Add(new Country() { Name = "Canada" }); } public void LoadCities(Country country) { if (country.Name == "US") { country.Cities.Add(new City() { Name = "NY", Count = 1 }); country.Cities.Add(new City() { Name = "Atlanta", Count = 2 }); } if (country.Name == "Canada") { country.Cities.Add(new City() { Name = "Toronto", Count = 3 }); country.Cities.Add(new City() { Name = "Vancouver", Count = 4 }); } } //here I call method that takes only country - means root item selected in the tree. public void LoadExtraData(Country country) { //call to WCF with parameter country SelectedCountry = country; } // here I need full path - country and city.. public void LoadExtraData(Country country, City city) { //call to WCF with parameters country and city SelectedCountry = country; SelectedCity = city; } }