ClearSelection not clearing SelectedPoints

3 posts, 1 answers
  1. Josh
    Josh avatar
    27 posts
    Member since:
    Feb 2012

    Posted 30 Jul 2012 Link to this post

    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. Answer
    Yavor
    Admin
    Yavor avatar
    401 posts

    Posted 02 Aug 2012 Link to this post

    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.

  3. DevCraft banner
  4. Josh
    Josh avatar
    27 posts
    Member since:
    Feb 2012

    Posted 02 Aug 2012 Link to this post

    That's exactly what I ended up doing after I removed the ClearSelection call, thanks for the feedback Yavor.
Back to Top