how to get itemclick by mouse right click?

3 posts, 0 answers
  1. Tony
    Tony avatar
    6 posts
    Member since:
    Sep 2011

    Posted 02 Nov 2012 Link to this post

    i can get itemclick by left click on chart, it's cool.
    but we need a function of the right click, it seems the right click do not have eventargs like left click.
    is there any way to solve this?
  2. Tony
    Tony avatar
    6 posts
    Member since:
    Sep 2011

    Posted 06 Nov 2012 Link to this post

    I believe i got this problem solved, not perfect but works.

    _chart.DefaultView.ChartArea.HoverChanged += new EventHandler<ChartHoverChangedEventArgs>(ChartArea_HoverChanged);

    Use this to save the datapoint hover.

    _chart.DefaultView.ChartArea.MouseRightButtonDown += new MouseButtonEventHandler(ChartArea_MouseRightButtonDown);

    In this read the data mouse hovered.

    But the important thing is, you have to set the selectionmode to item, not series!

  3. DevCraft banner
  4. Petar Kirov
    Admin
    Petar Kirov avatar
    425 posts

    Posted 07 Nov 2012 Link to this post

    Hello Tony,

    You don't need to use the HoverChanged event of the ChartArea to achieve this. Instead you can just use the ChartArea.HoveredItems collection straight in the MouseRightButtonDown event handler. Here is an example: 
    private void ChartArea_MouseRightButtonDown(object sender,MouseButtonEventArgs e)
    {
    var chartArea = this.chart.DefaultView.ChartArea;
     
    var currentItem = chartArea.HoveredItems.FirstOrDefault();
    var previouslySelectedItem = chartArea.SelectedItems.LastOrDefault();
     
    if (currentDataPoint != null && currentItem != previouslySelectedItem)
        chartArea.SelectItem(currentItem);
    else if (currentDataPoint != null && currentItem == previouslySelectedItem)
        chartArea.UnselectItem(currentDataPoint);
     
    e.Handled = true;
    }


    All the best,
    Petar Kirov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top