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

Get Selected Item Node of RadTreeMap in View Model and set un-select it

10 Answers 176 Views
TreeMap and PivotMap
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Ernie S
Top achievements
Rank 1
Ernie S asked on 21 Jul 2014, 03:20 PM
How to I get the selectec TreeMapItem of a Rad Tree Map in code so I can set IsSelected to false?  Best I have been able to do is get the Selected Item that is backing the node but not the node itself.

I have this:

<telerik:RadTreeMap x:Name="TreeMap"
                    IsSelectionEnabled="True"
                    ItemsSource="{Binding ChartItems}"
                    LayoutStrategy="Squarified" >
 
    <telerikControl:EventToCommandBehavior.EventBindings>
        <telerikControl:EventBinding EventName="SelectionChanged"
                                     Command="{Binding ShowDataCommand}"
                                     PassEventArgsToCommand="True"/>
    </telerikControl:EventToCommandBehavior.EventBindings>
     
    ..............
    ..............
 
</telerik:RadTreeMap>

The argument (SelectionChangedRoutedEventArgs) gets passed properly but the SelectedItem is the object from the ChartItems collection that has the backing data and not the "RadTreeMapItem" which, I presume, is what I need to unselect it.  In other works, this works:

SelectedChartItem = args.SelectedItem as ChartItem;

but this does NOT:

var SelectedTreeMapItem = args.SelectedItem as RadTreeMapItem;

I assume (hope) that the item is buried somewhere else in the argument object?

Thanks
Ernie

10 Answers, 1 is accepted

Sort by
0
Evgenia
Telerik team
answered on 24 Jul 2014, 01:02 PM
Hi Ernie,

I'm not sure why do you need such complex logic for selection of RadTreeMap items. You can wire to PreviewSelectionChanged event and just cancel the event like this:

private void RadTreeMap_PreviewSelectionChanged(object sender, SelectionChangedRoutedEventArgs e)
   {
       if (e.SelectedItem == null)
           e.Cancel = true;
   }

I also suggest that you review this online demo with source code provided where more complex selection of treemap items is demonstrated.

Let me know if you need any further assistance.

Regards,
Evgenia
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Ernie S
Top achievements
Rank 1
answered on 24 Jul 2014, 01:18 PM
What I am trying to show a popup that will display the details behind the selected chart item.  When the user closes the popup I want to the item they clicked on to be unselected.  And I want to do this in the ViewModel.  I can do with with PieCharts no problem like this:

var args = e as ChartSelectionChangedEventArgs;

DataPoint datapoint = args.AddedPoints.FirstOrDefault();
if (datapoint == null)
    return;
 
SelectedChartItem = datapoint.DataItem as ChartItem;
datapoint.IsSelected = false;

In this case the command binding passes the arguments as ChartSelectionChangedEventArgs which gets me access to the Charting DataPoint and the ability to change IsSelected.

I need to do the same thing with TreeMap but since, it seems, treemap does not have a custom Event Argument (seems the command is sent back with a SelectionChangedRoutedEventArgs type parameter) I do not see how to do the same thing.

Ernie

0
Evgenia
Telerik team
answered on 29 Jul 2014, 01:00 PM
Hello Augustine,

This is to inform you that we will need some more time to answer you. I'll contact you again till the end of the day. Thanks for your patience.

Regards,
Evgenia
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Accepted
Evgenia
Telerik team
answered on 29 Jul 2014, 02:14 PM
You might find attached a sample that uses CommandBindings and some selection related boolean ViewModel properties to represent the scenario you have. Please review it and tell us whether such approach is helpful. Also something to mention here - as you will see the TreeMapItem might be unselected not only on clicking the Popup but on deselecting the same item. I believe this is more intuitive and this is what most customers will expect.

Regards,
Evgenia
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Ernie S
Top achievements
Rank 1
answered on 30 Jul 2014, 10:18 PM
Thank you Evgenia.  I cannot get the project to compile - it complains about a missing resource dictionary. But I can see what it is trying to do - you can to use the code behind of the View rather then being able to do it in the View Model which was hoping to avoid but it seems to be the only way to go.

Thanks again,
Ernie
0
Ernie S
Top achievements
Rank 1
answered on 06 Aug 2014, 01:30 PM
Hi Evgenia.  I was able to implement the code you used in my code (still cannot get your example to compile).

I noticed that the deselection works but it seems the RadTreeMap.SelectedItem does not get updated.  If I click on an item for the first time and the .SelectedItem is non-null and running the for loop clears the IsSelected item so when the popup is closed the clicked item appears unselected.

But if I click on the SAME item again, the .SelectedItem of the tree map is NULL.  If if I click on a different item it works just fine.  Seems the IsSelected change does not fully notify the TreeMap object that it is no longer selected.  SelectedItem is read-only so is there a way to clear the backing object?

Thanks
Ernie
0
Accepted
Evgenia
Telerik team
answered on 11 Aug 2014, 11:52 AM
Hello Augustine,

Please mind that I added RadTreeMapItem Style in the project previously sent and this style is BasedOn existing RadTreeMapItemStyle and has no Key set. It gets applied without calling it anywhere. We do this when we want the styles to get applied implicitly. You can read more about this approach in our documentation, more specifically here. Here's why I'm mentioning this - I guess that you have missed to add reference to the theme assembly that is used as source for the implicit style files merged in App.xaml. This explains why you are observing a missing resource dictionary exception and the project does not compile. Could you please check whether this is the case on your side?
As for your last post - could you please send us a detailed steps that we should follow to reproduce your case? I'm not able to observe this by debugging the project I sent you.

Regards,
Evgenia
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Ernie S
Top achievements
Rank 1
answered on 11 Aug 2014, 01:00 PM
Thanks Evgenia.  I understand the implicit styles thing - I just do not seem to have the VisualStudio2013 theme you are using.  I just removed all references to it and the project now runs.

I am not sure what the problem is with my current code.  I am use the Telerik EventBinding object to call a command with the PassEventArgsToCommand set to true.  When I do this for some reason the second pass comes across as null.

I ended up just sending the entire treemap object back to the VM and used your children selection technique and that seems to work fine.

Ernie
0
Evgenia
Telerik team
answered on 14 Aug 2014, 10:51 AM
Hello Augustine,

The onliest reason I can find for the strange behavior that you observe is if you have specified a CommandParameter to your EventBinding. In this case the PassEventArgsToCommand value is ignored.
However I'm glad you managed to make this work. Feel free to drop us a line if there is anything else we can assist you with.

Regards,
Evgenia
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Ernie S
Top achievements
Rank 1
answered on 14 Aug 2014, 12:05 PM
Actually, if you look at my first post you will see exactly what I am doing if you wish to investigate it any further.

Thanks again for the help.

Ernie
Tags
TreeMap and PivotMap
Asked by
Ernie S
Top achievements
Rank 1
Answers by
Evgenia
Telerik team
Ernie S
Top achievements
Rank 1
Share this question
or