Determining bar clicked with contextd menu

5 posts, 1 answers
  1. Terry
    Terry avatar
    157 posts
    Member since:
    Jul 2009

    Posted 23 Feb 2010 Link to this post

    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

  2. Bartholomeo Rocca
    Bartholomeo Rocca avatar
    247 posts
    Member since:
    May 2006

    Posted 26 Feb 2010 Link to this post

    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.
  3. Terry
    Terry avatar
    157 posts
    Member since:
    Jul 2009

    Posted 28 Feb 2010 Link to this post

    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.
  4. Answer
    Giuseppe
    Admin
    Giuseppe avatar
    2363 posts

    Posted 03 Mar 2010 Link to this post

    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.
  5. Terry
    Terry avatar
    157 posts
    Member since:
    Jul 2009

    Posted 03 Mar 2010 Link to this post

    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

Back to Top