title: Using wpf datagrid with ironpython and sqlite3
body: <p>I am trying to figure out how to make use IronPython (2.6) wpf and sqlite3 (i use the Ironpython.SQLite.dll)</p>
  
  <p>I get somewhat stuck in how to use the wpf datagrid. </p>
  
  <p>Can anyone help me further in how to code in order to fill the datagrid </p>
  
  <p>with the data from the sqlite database thats made here.</p>
  
  <p>Below is the code on how far i got...
  1st the python xaml file
                  </p>
  
  <pre><code>                &lt;Grid&gt;
                        &lt;DataGrid Name="mydatagrid" ItemsSource="{Binding}" ColumnWidth="300" RowHeight="20" AutoGenerateColumns="True" Margin="12,370,242,25"  GridLinesVisibility="All" CanUserResizeRows="False"&gt;
                          &lt;DataGrid.Columns&gt;
                              &lt;DataGridTextColumn Binding="{Binding}" Header="Header" /&gt;
                              &lt;DataGridTextColumn Header="Header" /&gt;
                              &lt;DataGridTextColumn Header="Header" /&gt;
                          &lt;/DataGrid.Columns&gt;
                        &lt;/DataGrid&gt;
                  &lt;/Grid&gt;
              &lt;/Window&gt; 
  </code></pre>
  
  <p>Ant then below here the python code<br>
  myapp.py
                  import sys 
                  import nt 
                  import clr</p>
  
  <pre><code>            clr.AddReference('PresentationFramework')
  
              from System.IO import FileMode, FileStream
              from System.Windows import Application
              from System.Windows.Markup import XamlReader
  
              stream = FileStream('Myxaml.xaml', FileMode.Open)
              window = XamlReader.Load(stream)
              window.Title='My Program'
  
              sys.path.append(nt.getcwd())
              clr.AddReferenceToFile("IronPython.SQLite.dll")
              sys.path.append("C:\Program Files (x86)\IronPython 2.6 for .NET 4.0\Lib") 
  
              import os
              import _sqlite3
              from _sqlite3 import *
  
  
              DB_NAME = 'mydb.s3db'
  
              if not os.path.exists(DB_NAME):
                  #create new DB if not exist, 
                  con = _sqlite3.connect(DB_NAME)
                  con.execute(''' CREATE TABLE [mytable] 
                  (
                      [key] INTEGER  NOT NULL PRIMARY KEY AUTOINCREMENT,
                      [desc] NVARCHAR(30)  NULL,
                      [count1] FLOAT DEFAULT '0' NULL,
                      [count2] FLOAT DEFAULT '0' NULL
                      )''')        
                  con.execute('''insert into mytable (desc,count1,count2) values ("part1",1.4,10)''')
                  con.execute('''insert into mytable (desc,count1,count2) values ("part2",2.4,20)''')
                  con.execute('''insert into mytable (desc,count1,count2) values ("part3",3.4,30)''')
                  con.execute('''insert into mytable (desc,count1,count2) values ("part4",4.4,40)''')
                  con.execute('''insert into mytable (desc,count1,count2) values ("part5",5.4,50)''')
                  con.execute('''insert into mytable (desc,count1,count2) values ("part6",6.4,60)''')
                  con.commit()
              else:
                  #use existing DB
                  con = _sqlite3.connect(DB_NAME)
  
              grid1 = window.FindName('mydatagrid')
              cur=con.cursor()
              cur.execute("SELECT * FROM mytable")
              #grid1.ItemsSource=cur.fetchone()
              #grid1.DataContext=cur.fetchall()
              #print cur.fetchall()
              app = Application()
              app.Run(window)
  </code></pre>
  
  <p>I am a starter in this and might be completely on the wrong path, but i cant seem to find out what
  or how to fill the itemssource or datacontext or both... with anyway not with the commentet out options above...... </p>