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

Determining bar clicked with contextd menu

4 Answers 103 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Terry
Top achievements
Rank 1
Terry asked on 24 Feb 2010, 04:04 AM
Hi:

i was using the ChartItemClicked event to determine the bar that was clicked
(HCDA4.Web.Models.KPISummary summary = ((HCDA4.Web.Models.KPISummary)(args.DataPoint.DataItem));)
but now I am using your Silverlight 4 beta so I can bring up the context menu with a right-click.  Now I need to hook in someplace else, either in the context menu Opened event or the mouserightbuttondown event, but neither of these gives me any information as to which bar was clicked.  The items in the context menu vary depending upon the bar that is clicked, so I need to see the object that is bound to the clicked bar.

How can I do this?

Thanks,

Terry

4 Answers, 1 is accepted

Sort by
0
Bartholomeo Rocca
Top achievements
Rank 1
answered on 26 Feb 2010, 02:13 PM
Hello Terry,

Have you seen this blog post here -- it explains how to integrate context-specific context menu in RadChart.

Btw, it is also available as an example in the Q1 2010 Beta here. Hope this helps.


Greetings,
Bart.
0
Terry
Top achievements
Rank 1
answered on 28 Feb 2010, 06:06 PM
Thanks, Bart.  Wow!  That seems like a lot of work.  I may just go back to using a left-click, where this is all handled.

To Telerik: It's great that you have a Telerik-specific left-click event with the DataPoint property so I can easily see what bar on a chart was clicked.  Now that Silverlight 4 allows right-click, the normal Windows way to get a context menu, how about providing a Telerik specific right-click event for the chart, that does the same?  All we get currently is the standard mouse event argument, which knows nothing about the underlying chart.
0
Accepted
Giuseppe
Telerik team
answered on 03 Mar 2010, 11:25 AM
Hi Terry,

You can get the same information on the RadContextMenu.ItemClick event through the RadContextMenu.GetClickedElement<T>() method like this:

private void OnContextMenuClick(object sender, Telerik.Windows.RadRoutedEventArgs e)
{
    RadContextMenu contextMenu = (sender as RadContextMenu);
    BaseChartItem chartItem = contextMenu.GetClickedElement<BaseChartItem>();
    DataPoint dataPoint = chartItem.DataPoint;
    DataSeries dataSeries = chartItem.DataSeries;
 
    // Get the clicked item
    MenuItem menuItem = (e.OriginalSource as RadMenuItem).Header as MenuItem;
 
    if (menuItem.Text == "Foo 0")
    {
        //...
    }
}


Hope this helps.


Greetings,
Manuel
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Terry
Top achievements
Rank 1
answered on 03 Mar 2010, 03:48 PM
That's the solution!

Only, I want to change the menu items based upon the chart bar that is clicked, so I use the same code in the

Context_Menu_Opened event.

Thanks very much!  I knew there had to be a way to accomplish this.

Terry

Tags
Chart
Asked by
Terry
Top achievements
Rank 1
Answers by
Bartholomeo Rocca
Top achievements
Rank 1
Terry
Top achievements
Rank 1
Giuseppe
Telerik team
Share this question
or