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

how to get itemclick by mouse right click?

2 Answers 27 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Tony
Top achievements
Rank 1
Tony asked on 02 Nov 2012, 09:02 AM
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 Answers, 1 is accepted

Sort by
0
Tony
Top achievements
Rank 1
answered on 06 Nov 2012, 07:12 AM
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!

0
Petar Kirov
Telerik team
answered on 07 Nov 2012, 10:52 AM
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.

Tags
Chart
Asked by
Tony
Top achievements
Rank 1
Answers by
Tony
Top achievements
Rank 1
Petar Kirov
Telerik team
Share this question
or