Community & Support
Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WPF > Chart > DateRow conversion

Not answered DateRow conversion

Feed from this thread
  • Posted on Jun 26, 2009 (permalink)

    Hi,

    Based in the intergration sample I am trying to populate a chart from a grid. I have the following functions which I took from your sample. I have changed the function to use all records not just the selected ones.

           private void ShowSelectedRecordsInChart()  
            {  
     
                DataTable table = new DataTable();  
     
                DataColumn col = new DataColumn("Shuttle"typeof(double));  
     
                table.Columns.Add(col);  
     
                try 
                {  
                    foreach (DataRecord item in this.datagrdV02.Records)  
                    {  
                        DataRow row = table.NewRow();  
     
                        row["Shuttle"] = ((DataRow)item.Data)["Shuttle"];  
     
                        table.Rows.Add(row);  
                    }  
                }  
                catch (Exception ex)  
                {  
                    MessageBox.Show(ex.Message);  
                }   
            } 

    When I execure the following line:

    row[

    "Shuttle"] = ((DataRow)item.Data)["Shuttle"];

     


    I get the following error:

    Unable to cast object of type 'CoachTech.Test_VO2' to type 'System.Data.DataRow'.

    Any Idea what I am doing wrong?

    Cheers,
    Kevin.

    Reply

  • Vlad Vlad admin's avatar

    Posted on Jun 27, 2009 (permalink)

    Hi Kevin,

    Most probably the grid is not bound to DataTable and that is why you cannot case DataRecord.Data to DataRow.

    Best wishes,
    Vlad
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.

    Reply

  • Q1 Webinar Week
  • Posted on Jun 28, 2009 (permalink)

    Hi,

    The grid is populated using the following code...

                    var Results = from a in db.Test_VO2s  
                                  where a.AthleteID == AthleteID  
                                  select new 
                                  {  
                                      a.Date,  
                                      a.Shuttle,  
                                      a.VO2,  
                                      a.Max_Heart_Rate,  
                                      a.Level  
                                  };  
     
     
                    this.datagrdV02.ItemsSource = Results; 

    so as you can see its not bound to a DataTable. I have tried to get the Linq result to populate a DataTable but cant seem to get it ro work.

    and Ideas?

    I have set the chart ItemSoucrce to the Results var as well and that populates the chart but I will lose the intergration.

    Also I wanted to set the Date column from the query as the lable across the X axis. How do I do this?

    Cheers,
    Kevin.

    Reply

  • Ves Ves admin's avatar

    Posted on Jul 1, 2009 (permalink)

    Hi Kevin,

    The value of e.Item.DataItem is an object, which corresponds to that row in the grid. If the datasource is a DataTable e.Item.DataItem will hold a DataRow. If the datasource is a list of custom objects e.Item.DataItem will hold an instance of that custom object type.

    That said, if your code looked like this:
    var Results = from a in db.Test_VO2s   
         where a.AthleteID == AthleteID   
         select a ; 
      
    this.datagrdV02.ItemsSource = Results;  
    you would get that message and you could simply cast e.Item.DataItem to Test_VO2. However, your code snippet shows, that you use an anonymous type, so you would not be able to cast e.Item.DataItem. A possible solution would be to use the above code and a line like this:

    row["Shuttle"] = ((Test_VO2)(e.Item.DataItem).Shuttle;

    Alternatively, you can create your own type, containing only the properties you need (Date, Shuttle, VO2, Max_Heart_Rate and Level) and use it like this:

    var Results = from a in db.Test_VO2s    
         where a.AthleteID == AthleteID    
         select new MyType 
         { 
             Date = a.Date, Shuttle = a.Shuttle,...... 
         } 

    Hope this helps.

    Greetings,
    Ves
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WPF > Chart > DateRow conversion
Related resources for "DateRow conversion"

WPF Chart Features  |  Documentation  |  Demos  |  Telerik TV  |  Self-Paced Trainer  ]