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

ClearSelection not clearing SelectedPoints

2 Answers 81 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Josh
Top achievements
Rank 1
Josh asked on 30 Jul 2012, 09:25 PM
We are using ChartViews with AreaSeries to display summarized data over a period of time.  We then utilize the ChartSelectionBehavior.SelectionChanged event to open a detailed report for the date corresponding to the point on the chart that was clicked.  In testing, we noticed that after the initial time a point was clicked, it would take two clicks for each subsequent selection to be registered.  We realized that was intended as the point was being toggled from selected to unselected each time it was clicked; so not a problem, we'll just reset the selection each time.  That's where we are having trouble.

Here's some code to help explain the problem.
private void OnAreaChartSelected(object sender, ChartViewSelectionChangedEventArgs e)
{
            var selectedPoint = e.AddedPoints.FirstOrDefault();
            if(selectedPoint == null)
            {
                return;
            }
 
            // Do some work
 
 
           // Clear selection
            var chartBehavior = sender as ChartSelectionBehavior;
            if (chartBehavior != null)
                chartBehavior.ClearSelection();
}


So you can see that we try to clear the selection so each time the user clicks on a point, it'll be treated as if it's being selected.  But ClearSelection actually seems to exacerbate the issue.  We can put in a breakpoint after that call and see that the SelectedPoints property of the chart is still populated.  Clicking on the point again results in the event firing with both AddedPoints and RemovedPoints empty and the SelectedPoints collection still containing the point.  Clicking once again fires the event with RemovedPoints populated with the point and SelectedPoints empty.  Clicking one last time finally fires the event with AddedPoints populated. 

Are we misunderstanding what ClearSelection does?  If so, is there any way to implement what we are trying to do?

2 Answers, 1 is accepted

Sort by
0
Accepted
Yavor
Telerik team
answered on 02 Aug 2012, 11:44 AM
Hello Josh,

You are using it right, though there seems to be a bug in ClearSelection() method. I have logged this issue in our PITS system here.

If I understood correctly, you want to show some detailed information somewhere in your application each time the user clicks on an item in the chart? When you click on a selected item in the chart view it deselects itself, but still the SelectionChanged will be thrown. All newly selected items are passed in the e.AddedPoints, and all deselected - e.RemovedPoints. You can browse these 2 collections to determine if the user has selected or deselected a point and call your method with the correct item each time. No need to clear the selection each time something is selected.

All the best,
Yavor
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Josh
Top achievements
Rank 1
answered on 02 Aug 2012, 01:24 PM
That's exactly what I ended up doing after I removed the ClearSelection call, thanks for the feedback Yavor.
Tags
ChartView
Asked by
Josh
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Josh
Top achievements
Rank 1
Share this question
or