Skip to content

Using IronPython for a Data Source

New Discussion
Sven
Sven asked on Mar 29, 2011 9:39 AM

Hi,

we are using Silverlight with IronPython, so we generate the data with python.

Is it possible to create a data source with IronPython?

The main problem seems to implement the IEnumerable interface in python.


Sign In to post a reply

Replies

  • 0
    Atanas Dyulgerov
    Atanas Dyulgerov answered on Mar 22, 2011 10:34 AM

    Hi,

    I'm not an expert on IronPython, so you will have to verify if this would work for you.

    According to the IronPython documentation when you interact with .NET and the .NET method expects a different type of data than the one Python provides, automatic conversion will occur. The conversion will be successful when the two types are compatible. Again according to the docs IEnumerable<T> corresponds to a tuple with only elements with type T.

    So my guess is that you have to create a DataSource just as you would in a normal SIlverlight application, but at the point where you have to set the ItemsSource to an IEnumerable you will have to set it to a tuple of elements with unanimous type that comes from Python.

    I hope this is useful.

    All the best,
    Atanas

    • 0
      Sven
      Sven answered on Mar 25, 2011 3:23 PM

       

      Hi,

      thanx for the fast answer.

      May be with an example I can show you the problem:

      PythonCode:

       

              testDataMulitDimTuple = (
                  ( '','','','Men','Men','Men','Men','Men','Women','Women','Women','Women','Women' ),
                  ( '','','','Case','Percentage','Mio','Due Percentage','Index','Case','Percentage','Mio','Due Percentage','Index' ),
                  ( 'All','','',58283,100,34.84,49,100,55224,100,35.66,51,100),
                  ( 'All','Age','',4591,8.3,2.88,52,105,5511,7.5,2.69,48,95),
                  ( 'All','Age','14 - 19 years',8211,15,5.23,51,104,9732,13.9,4.97,49,96),
                  ( 'All','Age','20 - 29 years',10215,15.4,5.37,51,103,10081,14.4,5.15,49,97)
              )

              o_flatDataSource = FlatDataSource()
              o_flatDataSource.ItemsSource = testDataMulitDimTuple
              dataGrid.DataSource=o_flatDataSource

       

      With this I get an error: ArgumentException: An item with the same key has already been added.

       

       

      • 0
        [Infragistics] Todor Karkelanov
        [Infragistics] Todor Karkelanov answered on Mar 29, 2011 9:39 AM

        Hi

        I am afraid that you can’t set the itemsSource of flatdatasource as multidimensional array. The source should be array from business object. I mean that you should define class and define properties in this class for different elements from data. For example

         

        Public class Data

        {

                        Public string Gender{get; set;}

                        Public int Age{get;set;}

                        …..

        }

         

        After that create your array from Data and put it to pivot grid

        List<Data> list = new List<Data>();

        //populate list

         

         o_flatDataSource.ItemsSource = list;

         

        Regards

        Todor

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
Sven
Favorites
0
Replies
3
Created On
Mar 29, 2011
Last Post
15 years, 5 months ago

Suggested Discussions

Created by

Created on

Mar 29, 2011 9:39 AM

Last activity on

Mar 29, 2011 9:39 AM