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

Select a row in datagrid by clicking on scatterpoint

2 Answers 50 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Erwin
Top achievements
Rank 2
Erwin asked on 06 Jul 2011, 03:22 PM
I'm trying to get a row selected in a datagrid, by clicking on a datapoint in a scattergraph.

My datapoint class:

public class TelerikDataPoint : DataPoint
{
    public VMSalesLine line { get; private set; }
    private SalesLineCollection salesLinesCollection;
 
    public double Category { get; private set; }
    public double Value { get; private set; }
 
    public TelerikDataPoint(DateTime category, double value)
    {
        Category = category.ToOADate();
        Value = value;
    }
 
    public TelerikDataPoint(SalesLineCollection salesLinesCollection, VMSalesLine line)
    {
        this.salesLinesCollection = salesLinesCollection;
        this.line = line;
 
        this.Category = line.Data.PlannedDeliveryDate.Date.ToOADate();
        this.Value = line.Data.Amount.Value;
        this.Tooltip = line.Data.HeaderID + "-" + line.Data.LineNumber.ToString();
        
    }
}

In the datagrid I present sales lines, in the graph too.
The graph shows a few datapoint series, built like  "DeliveredOnTimeSeries.Add(dataPoint);"
(of the type ObservableCollection<TelerikDataPoint>) 

I have defined an itemclick method, and that's fired. I can also read out xvalue and yvalue of the clicked datapoint.

In the 'old' situation (before we started using Telerik controls) selecting the row in the datagrid was accomplished in the Datapoint Class as follows:

class MyDataPoint : DataPoint
{
    private VMSalesLine line;
    private SalesLineCollection salesLinesCollection;

    public MyDataPoint(SalesLineCollection salesLinesCollection, VMSalesLine line)
    {
        this.salesLinesCollection = salesLinesCollection;
        this.line = line;
        this.XValue = line.Data.PlannedDeliveryDate.Date;
        this.YValue = line.Data.Amount.Value;
        this.ToolTipText = line.Data.HeaderID + "-" + line.Data.LineNumber.ToString();
        this.MouseLeftButtonUp += new MouseButtonEventHandler(MyDataPoint_MouseLeftButtonUp);
    }

    void MyDataPoint_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
    {
        salesLinesCollection.SalesLines.MoveCurrentTo(line);
    }
}

How do I do this with the Telerik control? In the datapoint class there's no MouseLeftButtonUp 
and in the itemclick method I cannot reach/find the datapoint.line attribute.

If you need any more information, please let me know.



2 Answers, 1 is accepted

Sort by
0
Erwin
Top achievements
Rank 2
answered on 07 Jul 2011, 02:48 PM
I have solved this issue as follosw:

        public void ChartArea_ItemClick(object sender, ChartItemClickEventArgs e)
        {            
            TelerikDataPoint telerikDataPoint = e.DataPoint.DataItem as TelerikDataPoint;
            if (telerikDataPoint != null)
            {
                VMSalesLine line = telerikDataPoint.Line as VMSalesLine;
                if (line != null)
                {
                    salesLinesCollection.SalesLines.MoveCurrentTo(line);
                }
            }                 
        }

0
Missing User
answered on 07 Jul 2011, 04:53 PM
Hi Erwin,

We are glad to hear that you have resolved this issue. Just to clarify for other customers that can encounter this - if the RadChart is not data bound, the DataItem will be null. For example, the chart can be bound via its ItemsSource property:
 
ObservableCollection<CustomDataItem> myData = new ObservableCollection<CustomDataItem>();
myData.Add(dataItem1);
myData.Add(dataItem2);
...
myData.Add(dataItemN);
  
radChart.ItemsSource = myData;

After that the clicked data item can be accessed as followed:

void ChartArea_ItemClick(object sender, ChartItemClickEventArgs e)
{
    CustomDataItem myDataItem = e.DataPoint.DataItem as CustomDataItem;
}

Additional information on populating RadChart with data can be found here.

Kind regards,
Polina
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
Chart
Asked by
Erwin
Top achievements
Rank 2
Answers by
Erwin
Top achievements
Rank 2
Missing User
Share this question
or