For the life of me I can't successfully bind a list of class instances to a
data grid view.  I get the grid, with the correct column headers and correct
number of rows, but the cells are all empty.  Below is my most sophisticated
attempt.  Any pointers would be greatly appreciated.


import clr
import System

clr.AddReference('System.Windows.Forms')
import System.Windows.Forms as SWF


class Person(System.Object):

   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


class Form(SWF.Form):

   def __init__(self):
       SWF.Form.__init__(self)
       # Grid.
       self._people = people = []
       data = [
           ('Joe', 23),
           ('Bob', 8),
           ('Thomas', 32),
           ('Patrick', 41),
           ('Kathy', 19),
           ('Sue', 77),
           ]
       for name, age in data:
           people.append(Person(name, age))
       self._extent_binding_source = binding_source = SWF.BindingSource()
       binding_source.DataSource = people
       grid = SWF.DataGridView()
       grid.Columns.Add('Name', 'Name')
       grid.Columns.Add('Age', 'Age')
       grid.DataSource = binding_source
       grid.Dock = SWF.DockStyle.Fill
       self.Controls.Add(grid)


if __name__ == '__main__':
   SWF.Application.EnableVisualStyles()
   form = Form()
   SWF.Application.Run(form)


--
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

Reply via email to