<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Binding a Silverlight DataGrid to dynamic data Part 2 &#8211; editable data and INotifyPropertyChanged</title>
	<atom:link href="http://www.scottlogic.co.uk/blog/colin/2009/04/binding-a-silverlight-datagrid-to-dynamic-data-part-2-editable-data-and-inotifypropertychanged/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.scottlogic.co.uk/blog/colin/2009/04/binding-a-silverlight-datagrid-to-dynamic-data-part-2-editable-data-and-inotifypropertychanged/</link>
	<description>Colin Eberhardt&#039;s Adventures in .NET</description>
	<lastBuildDate>Thu, 09 Feb 2012 03:02:27 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Andre</title>
		<link>http://www.scottlogic.co.uk/blog/colin/2009/04/binding-a-silverlight-datagrid-to-dynamic-data-part-2-editable-data-and-inotifypropertychanged/#comment-67524</link>
		<dc:creator>Andre</dc:creator>
		<pubDate>Tue, 26 Jul 2011 15:31:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/colin/?p=275#comment-67524</guid>
		<description>Hello Colin,

I read your blog posting „Binding a Silverlight DataGrid to dynamic data Part 2 – editable data and INotifyPropertyChanged”.
Is it possible to bind some textboxes too, with a two-way binding to the datasource. I tried it below but it did not work.
public Page()
        {
     InitializeComponent();

            // generate some dummy data
            Random rand = new Random();
            for (int i = 0; i &lt; 200; i++)
            {
                Row row = new Row();
                row[&quot;Forename&quot;] = s_names[rand.Next(s_names.Length)];
                row[&quot;Surname&quot;] = s_surnames[rand.Next(s_surnames.Length)];
                row[&quot;Age&quot;] = rand.Next(40) + 10;
                row[&quot;Shoesize&quot;] = rand.Next(10) + 5;               
                _rows.Add(row);
            }

   		
     	     Binding binding = new Binding(&quot;Shoesize&quot;);
            binding.Mode = BindingMode.TwoWay;
            binding.Converter = new RowIndexConverter();
            binding.ConverterParameter = &quot;Shoesize&quot;;
           // binding.Source = _rows;
            textBox1.SetBinding(TextBox.TextProperty, binding);

            // bind to our DataGrid
            _dataGrid.ItemsSource = _rows;            
        }
}

Maybe you can give me a hint.

Best regards 
André</description>
		<content:encoded><![CDATA[<p>Hello Colin,</p>
<p>I read your blog posting „Binding a Silverlight DataGrid to dynamic data Part 2 – editable data and INotifyPropertyChanged”.<br />
Is it possible to bind some textboxes too, with a two-way binding to the datasource. I tried it below but it did not work.<br />
public Page()<br />
        {<br />
     InitializeComponent();</p>
<p>            // generate some dummy data<br />
            Random rand = new Random();<br />
            for (int i = 0; i &lt; 200; i++)<br />
            {<br />
                Row row = new Row();<br />
                row[&quot;Forename&quot;] = s_names[rand.Next(s_names.Length)];<br />
                row[&quot;Surname&quot;] = s_surnames[rand.Next(s_surnames.Length)];<br />
                row[&quot;Age&quot;] = rand.Next(40) + 10;<br />
                row[&quot;Shoesize&quot;] = rand.Next(10) + 5;<br />
                _rows.Add(row);<br />
            }</p>
<p>     	     Binding binding = new Binding(&quot;Shoesize&quot;);<br />
            binding.Mode = BindingMode.TwoWay;<br />
            binding.Converter = new RowIndexConverter();<br />
            binding.ConverterParameter = &quot;Shoesize&quot;;<br />
           // binding.Source = _rows;<br />
            textBox1.SetBinding(TextBox.TextProperty, binding);</p>
<p>            // bind to our DataGrid<br />
            _dataGrid.ItemsSource = _rows;<br />
        }<br />
}</p>
<p>Maybe you can give me a hint.</p>
<p>Best regards<br />
André</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: How I learnt Silverlight &#8211; a path of SL begginer &#171;  &#160;&#160;   Researcher ≠ Developer  &#160;&#160;   ∧ Researcher ∈ Developers</title>
		<link>http://www.scottlogic.co.uk/blog/colin/2009/04/binding-a-silverlight-datagrid-to-dynamic-data-part-2-editable-data-and-inotifypropertychanged/#comment-51171</link>
		<dc:creator>How I learnt Silverlight &#8211; a path of SL begginer &#171;  &#160;&#160;   Researcher ≠ Developer  &#160;&#160;   ∧ Researcher ∈ Developers</dc:creator>
		<pubDate>Tue, 19 Apr 2011 09:31:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/colin/?p=275#comment-51171</guid>
		<description>[...] http://www.scottlogic.co.uk/blog/colin/2009/04/binding-a-silverlight-datagrid-to-dynamic-data-part-2... [...]</description>
		<content:encoded><![CDATA[<p>[...] <a href="http://www.scottlogic.co.uk/blog/colin/2009/04/binding-a-silverlight-datagrid-to-dynamic-data-part-2.." rel="nofollow">http://www.scottlogic.co.uk/blog/colin/2009/04/binding-a-silverlight-datagrid-to-dynamic-data-part-2..</a>. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marcell</title>
		<link>http://www.scottlogic.co.uk/blog/colin/2009/04/binding-a-silverlight-datagrid-to-dynamic-data-part-2-editable-data-and-inotifypropertychanged/#comment-46760</link>
		<dc:creator>Marcell</dc:creator>
		<pubDate>Sat, 19 Mar 2011 11:06:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/colin/?p=275#comment-46760</guid>
		<description>Hi!

I just want to thank you this great post. You helped me a lot. This is the best datagrid description that I&#039;ve ever seen. Thanks again.

Marcell</description>
		<content:encoded><![CDATA[<p>Hi!</p>
<p>I just want to thank you this great post. You helped me a lot. This is the best datagrid description that I&#8217;ve ever seen. Thanks again.</p>
<p>Marcell</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: BalamBalam</title>
		<link>http://www.scottlogic.co.uk/blog/colin/2009/04/binding-a-silverlight-datagrid-to-dynamic-data-part-2-editable-data-and-inotifypropertychanged/#comment-41407</link>
		<dc:creator>BalamBalam</dc:creator>
		<pubDate>Sun, 13 Feb 2011 20:53:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/colin/?p=275#comment-41407</guid>
		<description>Not sure about SilverLight but with WPF can pass an index in the Path 
e.g. Binding=&quot;{Binding Path=Data[0]  
And you can even append a property name 
e.g. Binding=&quot;{Binding Path=Data[0].GridDisplayValue  
Dynamic columns without a converter

I have not tested editing 
Sample code below:

ObservableCollection GridRowsWithDynamicColumns = new ObservableCollection();
for (int i = 1; i &lt; 10; i++)
{ 
    GridRowsWithDynamicColumns.Add(new GridRowWithDynamicColumns(i));
}

DataGridTextColumn textColumn;
Binding myBinding;

// can mix a static column with dynamic
textColumn = new DataGridTextColumn();
myBinding = new Binding(&quot;RowID&quot;);
textColumn.Header = &quot;RowID&quot;;
textColumn.Binding = myBinding;
textColumn.IsReadOnly = true;
DataGrid4.Columns.Add(textColumn);
DataGrid4.FrozenColumnCount = 1;


GridRowWithDynamicColumns gridRowWithDynamicColumns = new GridRowWithDynamicColumns(0);
//gridRowWithDynamicColumns is just to get .GridDynamicColumns
for (int i = 0; i &lt; gridRowWithDynamicColumns.GridDynamicColumns.Count; i++)
{
    textColumn = new DataGridTextColumn();
    // the constructor is Path
    myBinding = new Binding(&quot;GridDynamicColumns[&quot; + i.ToString() + &quot;].DisplayValue&quot;);
    // myBinding.Converter = new RowIndexConverter2();  converter not required
    textColumn.Header = gridRowWithDynamicColumns.GridDynamicColumns[i].ColumnHeader;
    textColumn.Binding = myBinding;
    textColumn.IsReadOnly = true;
    DataGrid4.Columns.Add(textColumn);
}

DataGrid4.ItemsSource = GridRowsWithDynamicColumns;

... 

public class GridRowWithDynamicColumns
{
    private Int32 rowID;
    private List gridDynamicColumns = new List();

    public string RowID
    {
        get { return rowID.ToString(); }
    }

    public List GridDynamicColumns
    { 
        get { return gridDynamicColumns; }
    }

    public GridRowWithDynamicColumns(Int32 RowID)
    {
        rowID = RowID;
        gridDynamicColumns.Add(new GridDynamicColumn(rowID, &quot;ColumnA&quot;));
        gridDynamicColumns.Add(new GridDynamicColumn(rowID, &quot;ColumnB&quot;));
        gridDynamicColumns.Add(new GridDynamicColumn(rowID, &quot;ColumnC&quot;));
        gridDynamicColumns.Add(new GridDynamicColumn(rowID, &quot;ColumnD&quot;));
        // Debug.WriteLine(gridDynamicColumns[0].DisplayValue);
    }
}

public class GridDynamicColumn
{
    private string columnHeader;
    private Int32 rowID;

    public GridDynamicColumn(Int32 RowID, string ColumnHeader)
    {
        rowID = RowID;
        columnHeader = ColumnHeader;
    }

    public string DisplayValue
    { 
        get 
        { 
            return rowID.ToString() + &quot; &quot; +  columnHeader;
            // this could be much more complex such as a call to database 
            // any parameters passed in the constructor are available 
            // or could implement a mutator and pass DisplayValue in the constructor
        }
    }

    public Int32 RowID
    {
        get
        {
            return rowID;
        }   
    }

    public string ColumnHeader
    {
        get
        {
            return columnHeader;
        }
    }
}</description>
		<content:encoded><![CDATA[<p>Not sure about SilverLight but with WPF can pass an index in the Path<br />
e.g. Binding=&#8221;{Binding Path=Data[0]<br />
And you can even append a property name<br />
e.g. Binding=&#8221;{Binding Path=Data[0].GridDisplayValue<br />
Dynamic columns without a converter</p>
<p>I have not tested editing<br />
Sample code below:</p>
<p>ObservableCollection GridRowsWithDynamicColumns = new ObservableCollection();<br />
for (int i = 1; i &lt; 10; i++)<br />
{<br />
    GridRowsWithDynamicColumns.Add(new GridRowWithDynamicColumns(i));<br />
}</p>
<p>DataGridTextColumn textColumn;<br />
Binding myBinding;</p>
<p>// can mix a static column with dynamic<br />
textColumn = new DataGridTextColumn();<br />
myBinding = new Binding(&quot;RowID&quot;);<br />
textColumn.Header = &quot;RowID&quot;;<br />
textColumn.Binding = myBinding;<br />
textColumn.IsReadOnly = true;<br />
DataGrid4.Columns.Add(textColumn);<br />
DataGrid4.FrozenColumnCount = 1;</p>
<p>GridRowWithDynamicColumns gridRowWithDynamicColumns = new GridRowWithDynamicColumns(0);<br />
//gridRowWithDynamicColumns is just to get .GridDynamicColumns<br />
for (int i = 0; i &lt; gridRowWithDynamicColumns.GridDynamicColumns.Count; i++)<br />
{<br />
    textColumn = new DataGridTextColumn();<br />
    // the constructor is Path<br />
    myBinding = new Binding(&quot;GridDynamicColumns[&quot; + i.ToString() + &quot;].DisplayValue&quot;);<br />
    // myBinding.Converter = new RowIndexConverter2();  converter not required<br />
    textColumn.Header = gridRowWithDynamicColumns.GridDynamicColumns[i].ColumnHeader;<br />
    textColumn.Binding = myBinding;<br />
    textColumn.IsReadOnly = true;<br />
    DataGrid4.Columns.Add(textColumn);<br />
}</p>
<p>DataGrid4.ItemsSource = GridRowsWithDynamicColumns;</p>
<p>&#8230; </p>
<p>public class GridRowWithDynamicColumns<br />
{<br />
    private Int32 rowID;<br />
    private List gridDynamicColumns = new List();</p>
<p>    public string RowID<br />
    {<br />
        get { return rowID.ToString(); }<br />
    }</p>
<p>    public List GridDynamicColumns<br />
    {<br />
        get { return gridDynamicColumns; }<br />
    }</p>
<p>    public GridRowWithDynamicColumns(Int32 RowID)<br />
    {<br />
        rowID = RowID;<br />
        gridDynamicColumns.Add(new GridDynamicColumn(rowID, &#8220;ColumnA&#8221;));<br />
        gridDynamicColumns.Add(new GridDynamicColumn(rowID, &#8220;ColumnB&#8221;));<br />
        gridDynamicColumns.Add(new GridDynamicColumn(rowID, &#8220;ColumnC&#8221;));<br />
        gridDynamicColumns.Add(new GridDynamicColumn(rowID, &#8220;ColumnD&#8221;));<br />
        // Debug.WriteLine(gridDynamicColumns[0].DisplayValue);<br />
    }<br />
}</p>
<p>public class GridDynamicColumn<br />
{<br />
    private string columnHeader;<br />
    private Int32 rowID;</p>
<p>    public GridDynamicColumn(Int32 RowID, string ColumnHeader)<br />
    {<br />
        rowID = RowID;<br />
        columnHeader = ColumnHeader;<br />
    }</p>
<p>    public string DisplayValue<br />
    {<br />
        get<br />
        {<br />
            return rowID.ToString() + &#8221; &#8221; +  columnHeader;<br />
            // this could be much more complex such as a call to database<br />
            // any parameters passed in the constructor are available<br />
            // or could implement a mutator and pass DisplayValue in the constructor<br />
        }<br />
    }</p>
<p>    public Int32 RowID<br />
    {<br />
        get<br />
        {<br />
            return rowID;<br />
        }<br />
    }</p>
<p>    public string ColumnHeader<br />
    {<br />
        get<br />
        {<br />
            return columnHeader;<br />
        }<br />
    }<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: BalamBalam</title>
		<link>http://www.scottlogic.co.uk/blog/colin/2009/04/binding-a-silverlight-datagrid-to-dynamic-data-part-2-editable-data-and-inotifypropertychanged/#comment-40363</link>
		<dc:creator>BalamBalam</dc:creator>
		<pubDate>Tue, 08 Feb 2011 15:18:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/colin/?p=275#comment-40363</guid>
		<description>I ported this over to WPF and where it breaks is the call to Convert after a cell edit.   At that point a row is not passed.  This seemed to fix it:
 
public object Convert(object value, Type targetType, object parameter, ...)
{
    Debug.WriteLine(value.GetType());
    string index = parameter as string;
    if (value.GetType() == typeof(Row))
    {
        Debug.WriteLine(&quot;Row&quot;);
        Row row = value as Row;
        return row[index];
    }
    else if (value.GetType() == typeof(PropertyValueChange))
    {
        Debug.WriteLine(&quot;PropertyValueChange&quot;);
        PropertyValueChange pvc = value as PropertyValueChange;
        return pvc.Value;
    }
    else
    {
        throw new NotImplementedException();
    }
}

I have not implemented or tested sorting in WPF .NET 4.0</description>
		<content:encoded><![CDATA[<p>I ported this over to WPF and where it breaks is the call to Convert after a cell edit.   At that point a row is not passed.  This seemed to fix it:</p>
<p>public object Convert(object value, Type targetType, object parameter, &#8230;)<br />
{<br />
    Debug.WriteLine(value.GetType());<br />
    string index = parameter as string;<br />
    if (value.GetType() == typeof(Row))<br />
    {<br />
        Debug.WriteLine(&#8220;Row&#8221;);<br />
        Row row = value as Row;<br />
        return row[index];<br />
    }<br />
    else if (value.GetType() == typeof(PropertyValueChange))<br />
    {<br />
        Debug.WriteLine(&#8220;PropertyValueChange&#8221;);<br />
        PropertyValueChange pvc = value as PropertyValueChange;<br />
        return pvc.Value;<br />
    }<br />
    else<br />
    {<br />
        throw new NotImplementedException();<br />
    }<br />
}</p>
<p>I have not implemented or tested sorting in WPF .NET 4.0</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pb</title>
		<link>http://www.scottlogic.co.uk/blog/colin/2009/04/binding-a-silverlight-datagrid-to-dynamic-data-part-2-editable-data-and-inotifypropertychanged/#comment-29515</link>
		<dc:creator>pb</dc:creator>
		<pubDate>Fri, 10 Dec 2010 16:53:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/colin/?p=275#comment-29515</guid>
		<description>firing property changed on Item[PropertyName] works in SL4</description>
		<content:encoded><![CDATA[<p>firing property changed on Item[PropertyName] works in SL4</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Colin Eberhardt</title>
		<link>http://www.scottlogic.co.uk/blog/colin/2009/04/binding-a-silverlight-datagrid-to-dynamic-data-part-2-editable-data-and-inotifypropertychanged/#comment-21598</link>
		<dc:creator>Colin Eberhardt</dc:creator>
		<pubDate>Mon, 11 Oct 2010 08:54:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/colin/?p=275#comment-21598</guid>
		<description>Take a look at Mike T&#039;s blog post:

http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2009/11/18/silverlight-4-rough-notes-binding.aspx

Colin E.</description>
		<content:encoded><![CDATA[<p>Take a look at Mike T&#8217;s blog post:</p>
<p><a href="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2009/11/18/silverlight-4-rough-notes-binding.aspx" rel="nofollow">http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2009/11/18/silverlight-4-rough-notes-binding.aspx</a></p>
<p>Colin E.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrus</title>
		<link>http://www.scottlogic.co.uk/blog/colin/2009/04/binding-a-silverlight-datagrid-to-dynamic-data-part-2-editable-data-and-inotifypropertychanged/#comment-21119</link>
		<dc:creator>Andrus</dc:creator>
		<pubDate>Mon, 04 Oct 2010 18:47:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/colin/?p=275#comment-21119</guid>
		<description>Silverlight 4 can bind to indexers. How to change this code to use indexes. This is lot cleaner than using valueconverters.</description>
		<content:encoded><![CDATA[<p>Silverlight 4 can bind to indexers. How to change this code to use indexes. This is lot cleaner than using valueconverters.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

