As far as I can tell the issue here seems to be that the data source is getting
the column names from the list and not from the individual elements that are
being added to the list. For example I tried the code below which hooks the
ColumnAdded event to see what columns are actually getting added. In that case
we end up adding columns for all of the methods on the List class. I seem to
get the same behavior if I use an array for my data source as well.
We do implement ICustomTypeDescriptor on all user-defined types (both new-style
and old-style) and this functionality does appear to work, eg:
x = MD('Foo', 23)
from System.ComponentModel import ICustomTypeDescriptor
for a in ICustomTypeDescriptor.GetProperties(x): print a.Name, a.GetValue(x)
prints:
name Foo
age 23
__doc__ None
__module__ __main__
__init__ <bound method MD.__init__ of <__main__.MD instance at
0x00000000000000FB>>
Name Foo
Age 23
But the DataGridView doesn't seem to be looking at the individual items. Feel
free to open a bug on this and please include the repros you had before.
import clr
clr.AddReference('System.Windows.Forms')
import System.Windows.Forms as SWF
from System import Array
from System.Collections.Generic import List
from System.ComponentModel import IListSource
class MD:
def __init__(self, name, age):
self.name = name
self.age = age
@property
def Name(self): return self.name
@property
def Age(self): return self.age
instType = type(MD('a', 2))
class Form(SWF.Form):
def __init__(self):
grid = SWF.DataGridView()
self.grid = grid
grid.DataSource = List[object]( ( MD('abc',23), ) )
grid.Dock = SWF.DockStyle.Fill
self.Controls.Add(grid)
grid.ColumnAdded += self.ColumnAdded
def ColumnAdded(self, sender, *args):
print self, sender, args
for x in self.grid.Columns: print x
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Patrick O'Brien
Sent: Wednesday, December 06, 2006 1:48 PM
To: Discussion of IronPython
Subject: Re: [IronPython] Data binding - how?
On 12/3/06, Luis M. González <[EMAIL PROTECTED]<mailto:[EMAIL PROTECTED]>>
wrote:
I guess the problem is in the properties you defined in "Person".
I tried this script, but importing "Person" from an assembly writen in C#, and
it worked.
So I assume that python properties are not recognized as .Net properties, and
they are needed to create the columns of the datagridview control.
I've pretty much given up on getting data binding to work correctly with
instances of Python classes, at least for now. But it would be nice to know if
I'm right or wrong, if I should file any bug reports, if there are any plans to
make this work any time soon, etc. Would anyone from the IronPython team care
to comment?
--
Patrick K. O'Brien
Orbtech http://www.orbtech.com
Schevo http://www.schevo.org
Louie http://www.pylouie.org
_______________________________________________
users mailing list
[email protected]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com