<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Scott Morrison : Sorting</title><link>http://blogs.msdn.com/scmorris/archive/tags/Sorting/default.aspx</link><description>Tags: Sorting</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Silverlight 2 DataGrid is Released</title><link>http://blogs.msdn.com/scmorris/archive/2008/10/14/silverlight-2-datagrid-is-released.aspx</link><pubDate>Wed, 15 Oct 2008 09:43:53 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9000390</guid><dc:creator>scmorris</dc:creator><slash:comments>21</slash:comments><comments>http://blogs.msdn.com/scmorris/comments/9000390.aspx</comments><wfw:commentRss>http://blogs.msdn.com/scmorris/commentrss.aspx?PostID=9000390</wfw:commentRss><description>&lt;p&gt;&lt;a href="http://weblogs.asp.net/scottgu/archive/2008/10/14/silverlight-2-released.aspx" target="_blank"&gt;As you might have heard&lt;/a&gt;, we just released &lt;a href="http://silverlight.net/GetStarted/" target="_blank"&gt;Silverlight 2&lt;/a&gt;, and with it the first version of the Silverlight DataGrid!&amp;#160; We have been building this for a while, giving the first glimpse of it last March in Silverlight 2 Beta 1, and tweaking it ever since based on your feedback.&amp;#160; We were able to pack a lot of great features into it, and I look forward to hearing from you what features you want next!&amp;#160; &lt;/p&gt;  &lt;p&gt;In celebration of its release, all of the &lt;a href="http://blogs.msdn.com/scmorris/archive/tags/DataGrid/default.aspx" target="_blank"&gt;previous walkthroughs&lt;/a&gt; have been updated to work with the RTW bits, and new walkthroughs are on their way.&amp;#160; &lt;/p&gt;  &lt;p&gt;Also, if you have never used the Silverlight DataGrid before, &lt;a href="http://blogs.msdn.com/scmorris/archive/2008/03/21/using-the-silverlight-datagrid.aspx" target="_blank"&gt;here is a good place to start&lt;/a&gt;.&lt;/p&gt;  &lt;h3&gt;What's New?&lt;/h3&gt;  &lt;p&gt;You might be wondering what has changed since Beta 2:&lt;/p&gt;  &lt;table width="100%"&gt;&lt;tbody&gt;     &lt;tr valign="top"&gt;       &lt;td&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 10px 10px 0px; border-right-width: 0px" height="172" alt="Automation" src="http://blogs.msdn.com/blogfiles/scmorris/WindowsLiveWriter/Silverlight2DataGridisReleased_C8C4/Automation_6e110932-8a7c-49c1-937d-19738ae80695.jpg" width="129" border="0" /&gt; &lt;/td&gt;        &lt;td&gt;         &lt;h4&gt;Accessibility: &lt;/h4&gt;          &lt;p&gt;One of the biggest features that we have added since Beta 2 is the addition of an automation peer framework which allows the DataGrid to work well with screen readers.&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr valign="top"&gt;       &lt;td&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 10px 10px 0px; border-right-width: 0px" height="179" alt="VSM" src="http://blogs.msdn.com/blogfiles/scmorris/WindowsLiveWriter/Silverlight2DataGridisReleased_C8C4/VSM_0b87db00-ad2f-4a15-816c-31009eab0d9a.png" width="129" border="0" /&gt; &lt;/td&gt;        &lt;td&gt;         &lt;h4&gt;Support for the VSM: &lt;/h4&gt;          &lt;p&gt;The Visual State Manager (VSM) is a tool that allows designers to customize how a control looks in various states, and the animations used to switch between these states.&lt;/p&gt;          &lt;p&gt;&lt;a href="http://blogs.msdn.com/expression/archive/2008/07/11/more-articles-on-visual-state-manager.aspx" target="_blank"&gt;Read more about the Visual State Manager...&lt;/a&gt;&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr valign="top"&gt;       &lt;td&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 10px 10px 0px; border-right-width: 0px" height="179" alt="Performance" src="http://blogs.msdn.com/blogfiles/scmorris/WindowsLiveWriter/Silverlight2DataGridisReleased_C8C4/Performance_9c404d48-3526-468a-a786-78787e8426b2.jpg" width="129" border="0" /&gt; &lt;/td&gt;        &lt;td&gt;         &lt;h4&gt;Performance, Performance, Performance:&lt;/h4&gt;          &lt;p&gt;We have done a lot in this area to try to get the DataGrid running as fast as possible. If the last time you used it was in Beta 1 or even Beta 2, you should definitely take another look. &lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr valign="top"&gt;       &lt;td&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 5px 10px 10px 0px; border-right-width: 0px" height="179" alt="API" src="http://blogs.msdn.com/blogfiles/scmorris/WindowsLiveWriter/Silverlight2DataGridisReleased_C8C4/API_823651ff-5015-4b74-81d8-acb4af779c64.png" width="129" border="0" /&gt; &lt;/td&gt;        &lt;td&gt;         &lt;h4&gt;API Improvements: &lt;/h4&gt;          &lt;p&gt;Based on your feedback, we took another pass through the API in an effort to simplify it more and give you more control over the DataGrid.&lt;/p&gt;          &lt;p&gt;&lt;a href="http://blogs.msdn.com/scmorris/archive/2008/10/15/post-beta-2-breaking-changes.aspx"&gt;Read about the Breaking Changes since Beta 2...&lt;/a&gt;&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr valign="top"&gt;       &lt;td&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 10px 10px 0px; border-right-width: 0px" height="179" alt="NewLook" src="http://blogs.msdn.com/blogfiles/scmorris/WindowsLiveWriter/Silverlight2DataGridisReleased_C8C4/NewLook_7a03c298-9617-4f06-a031-deb31c6ae7a2.jpg" width="129" border="0" /&gt; &lt;/td&gt;        &lt;td&gt;         &lt;h4&gt;Great New Look: &lt;/h4&gt;          &lt;p&gt;The entire framework got a visual upgrade since Beta 2, and the DataGrid is no exception.&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;h3&gt;What's Else Can It Do?&lt;/h3&gt;  &lt;p&gt;For those of you new to the Silverlight DataGrid, here is a quick rundown of what it could already do:&lt;/p&gt;  &lt;table&gt;&lt;tbody&gt;     &lt;tr valign="top"&gt;       &lt;td&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 10px 10px 0px; border-right-width: 0px" height="179" alt="AutoSized" src="http://blogs.msdn.com/blogfiles/scmorris/WindowsLiveWriter/Silverlight2DataGridisReleased_C8C4/AutoSized_e44a613e-8c5e-4f25-b20e-795402123c8c.jpg" width="129" border="0" /&gt; &lt;/td&gt;        &lt;td&gt;         &lt;h4&gt;Auto-sizing: &lt;/h4&gt;          &lt;p&gt;Everything in the DataGrid can be auto-sized.&amp;#160; That includes the DataGrid itself, Columns, Rows, Headers, and Row Details meaning that you do not have to worry about the size of what you are putting into the DataGrid, it will grow to accommodate it. &lt;/p&gt;          &lt;p&gt;&lt;a href="http://blogs.msdn.com/scmorris/archive/2008/06/10/auto-sizing-the-silverlight-datagrid.aspx" target="_blank"&gt;Read more about Auto-sizing...&lt;/a&gt;&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr valign="top"&gt;       &lt;td&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 10px 10px 0px; border-right-width: 0px" height="179" alt="NewLook" src="http://blogs.msdn.com/blogfiles/scmorris/WindowsLiveWriter/Silverlight2DataGridisReleased_C8C4/NewLook_7a03c298-9617-4f06-a031-deb31c6ae7a2.jpg" width="129" border="0" /&gt;&lt;/td&gt;        &lt;td&gt;         &lt;h4&gt;Sorting:&lt;/h4&gt;          &lt;p&gt;Any time you bind the DataGrid to a collection that implements IList such as a List&amp;lt;T&amp;gt; you now get sorting for free.&amp;#160; Even better, sorting isn't limited to a single column, but end users can sort by multiple columns by holding Shift and clicking on additional column headers. As an RTM improvement, you can also choose which columns you want to support sorting. &lt;/p&gt;          &lt;p&gt;&lt;a href="http://blogs.msdn.com/scmorris/archive/2008/06/10/sorting-data-in-the-silverlight-datagrid.aspx" target="_blank"&gt;Read more about Sorting...&lt;/a&gt;&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr valign="top"&gt;       &lt;td&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 10px 10px 0px; border-right-width: 0px" height="179" alt="Reorder" src="http://blogs.msdn.com/blogfiles/scmorris/WindowsLiveWriter/Silverlight2DataGridisReleased_C8C4/Reorder_6f7d9d77-5d26-42ff-b902-db9b42c4545c.jpg" width="129" border="0" /&gt;&amp;#160;&lt;/td&gt;        &lt;td&gt;         &lt;h4&gt;&lt;strong&gt;Column Reordering:&lt;/strong&gt; &lt;/h4&gt;          &lt;p&gt;End users can reorder columns at runtime just by dragging a column's header, and developers can control not only the order, but the appearance of the reordering UI as well as the behavior. &lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr valign="top"&gt;       &lt;td&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 10px 10px 0px; border-right-width: 0px" height="179" alt="Resize" src="http://blogs.msdn.com/blogfiles/scmorris/WindowsLiveWriter/Silverlight2DataGridisReleased_C8C4/Resize_47ad8959-cc35-4692-ba31-1e6071c20500.jpg" width="129" border="0" /&gt;&lt;/td&gt;        &lt;td&gt;         &lt;h4&gt;Column Resizing:&lt;/h4&gt;          &lt;p&gt;Just like reordering, and sorting, end users can control the size of columns at runtime. &lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr valign="top"&gt;       &lt;td&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 10px 10px 0px; border-right-width: 0px" height="179" alt="FrozenColumns" src="http://blogs.msdn.com/blogfiles/scmorris/WindowsLiveWriter/Silverlight2DataGridisReleased_C8C4/FrozenColumns_88b4d009-55d1-4d33-bb3f-6ac4d82c9a34.jpg" width="129" border="0" /&gt; &lt;/td&gt;        &lt;td&gt;         &lt;h4&gt;Frozen Columns: &lt;/h4&gt;          &lt;p&gt;This is a semi-advanced feature, but once you know about it you'll be surprised at how useful it can be.&amp;#160; A frozen column does not scroll horizontally but rather is &amp;quot;frozen&amp;quot; in place.&amp;#160; This is the same as the Freeze Column feature in Excel. &lt;/p&gt;          &lt;p&gt;&lt;a href="http://blogs.msdn.com/scmorris/archive/2008/10/15/freezing-columns-in-the-silverlight-datagrid.aspx" target="_blank"&gt;Read more about Freezing Columns...&lt;/a&gt;&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr valign="top"&gt;       &lt;td&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 10px 10px 0px; border-right-width: 0px" height="179" alt="RowDetails" src="http://blogs.msdn.com/blogfiles/scmorris/WindowsLiveWriter/Silverlight2DataGridisReleased_C8C4/RowDetails_4756094e-f1fb-47c8-9b28-d2ffd9d5568b.jpg" width="129" border="0" /&gt; &lt;/td&gt;        &lt;td&gt;         &lt;h4&gt;Row Details:&lt;/h4&gt;          &lt;p&gt;This feature is one that we are very excited about.&amp;#160; In short, it is an area in each row that allows you to put any UI you want that spans all columns.&amp;#160; This could be anything from form-based entry to the contents of a column that would do better if given more space. &lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr valign="top"&gt;       &lt;td&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 10px 10px 0px; border-right-width: 0px" height="179" alt="AutoGeneration" src="http://blogs.msdn.com/blogfiles/scmorris/WindowsLiveWriter/Silverlight2DataGridisReleased_C8C4/AutoGeneration_f9a4fdae-ca3b-4a43-a0e6-f4f2e5095f00.jpg" width="129" border="0" /&gt; &lt;/td&gt;        &lt;td&gt;         &lt;h4&gt;Auto-Generation of Columns: &lt;/h4&gt;          &lt;p&gt;A great feature to help get an application up and running quickly, auto-generation of columns creates a column for every property on the item that it is bound to. &lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr valign="top"&gt;       &lt;td&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 10px 10px 0px; border-right-width: 0px" height="179" alt="Skinnable" src="http://blogs.msdn.com/blogfiles/scmorris/WindowsLiveWriter/Silverlight2DataGridisReleased_C8C4/Skinnable_7ef3c20c-c8d0-4e06-8011-c91ea20312f1.jpg" width="129" border="0" /&gt; &lt;/td&gt;        &lt;td&gt;         &lt;h4&gt;Highly Customizable Visuals: &lt;/h4&gt;          &lt;p&gt;The look of the Silverlight 2 DataGrid has been improved, but it doesn't mean that you can't change it.&amp;#160; Every aspect of the DataGrid's appearance can be retemplated to create a drastically different looking DataGrid that maintains all of the great features listed here. &lt;/p&gt;          &lt;p&gt;&lt;a href="http://blogs.msdn.com/corrinab/archive/tags/Control+Skins/default.aspx" target="_blank"&gt;Read more about Customizing Control Visuals...&lt;/a&gt;&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr valign="top"&gt;       &lt;td&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 10px 10px 0px; border-right-width: 0px" height="179" alt="Edit" src="http://blogs.msdn.com/blogfiles/scmorris/WindowsLiveWriter/Silverlight2DataGridisReleased_C8C4/Edit_bda5e11f-8a67-4069-924f-8622238b3265.jpg" width="129" border="0" /&gt; &lt;/td&gt;        &lt;td&gt;         &lt;h4&gt;Editable: &lt;/h4&gt;          &lt;p&gt;The DataGrid control allows your users to edit the data that it is bound to.&amp;#160; One benefit of the Silverlight DataGrid is that it gives you control over what control is used to display the data for each cell, and what control is used to edit the data for each cell even if they are different.&amp;#160; The customization is easy, and it handles switching between the two when the user wants to go into edit mode. &lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr valign="top"&gt;       &lt;td&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 10px 10px 0px; border-right-width: 0px" height="179" alt="Scrollable" src="http://blogs.msdn.com/blogfiles/scmorris/WindowsLiveWriter/Silverlight2DataGridisReleased_C8C4/Scrollable_84ca9a5d-bc1a-4a2d-b661-86228676f592.jpg" width="129" border="0" /&gt; &lt;/td&gt;        &lt;td&gt;         &lt;h4&gt;Scrollable: &lt;/h4&gt;          &lt;p&gt;Another benefit that the DataGrid provides is the ability to scroll through long lists of data.&amp;#160; The DataGrid does a lot behind the scenes to make this experience as smooth as possible for your users even when you have a large number of rows.&amp;#160; You can also scroll columns and items into view to make sure that an item you want to highlight to your user is visible on screen. &lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr valign="top"&gt;       &lt;td&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 10px 10px 0px; border-right-width: 0px" height="179" alt="MultiSelect" src="http://blogs.msdn.com/blogfiles/scmorris/WindowsLiveWriter/Silverlight2DataGridisReleased_C8C4/MultiSelect_a1331575-053a-42c2-92e9-ba14cf240c67.jpg" width="129" border="0" /&gt; &lt;/td&gt;        &lt;td&gt;         &lt;h4&gt;Multi-Selection:&lt;/h4&gt;          &lt;p&gt;The DataGrid provides both single as well as extended selection modes, allowing you to choose if you want users to be able to select more than one row at a time &lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr valign="top"&gt;       &lt;td&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 10px 10px 0px; border-right-width: 0px" height="179" alt="ColumnTypes" src="http://blogs.msdn.com/blogfiles/scmorris/WindowsLiveWriter/Silverlight2DataGridisReleased_C8C4/ColumnTypes_b1abe567-c622-478b-9f89-1078b06cb815.jpg" width="129" border="0" /&gt; &lt;/td&gt;        &lt;td&gt;         &lt;h4&gt;Built-in Column Types: &lt;/h4&gt;          &lt;p&gt;Out of the box you can use both Text columns as well as CheckBox columns, and creating your own column types is easy.&lt;/p&gt;          &lt;p&gt;Read more about using the Built-in Column Types:&lt;/p&gt;          &lt;ul&gt;           &lt;li&gt;&lt;a href="http://blogs.msdn.com/scmorris/archive/2008/03/27/defining-columns-for-a-silverlight-datagrid.aspx" target="_blank"&gt;In XAML&lt;/a&gt; &lt;/li&gt;            &lt;li&gt;&lt;a href="http://blogs.msdn.com/scmorris/archive/2008/04/14/defining-silverlight-datagrid-columns-at-runtime.aspx" target="_blank"&gt;In Code Behind at Runtime&lt;/a&gt; &lt;/li&gt;         &lt;/ul&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr valign="top"&gt;       &lt;td&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 10px 0px 0px; border-right-width: 0px" height="179" alt="TemplateColumn" src="http://blogs.msdn.com/blogfiles/scmorris/WindowsLiveWriter/Silverlight2DataGridisReleased_C8C4/TemplateColumn_99a53b6c-8bc3-46e3-a02a-c517f8d70884.jpg" width="129" border="0" /&gt;&lt;/td&gt;        &lt;td&gt;         &lt;h4&gt;Template Column:&lt;/h4&gt;          &lt;p&gt;In addition to the built-in column types, the template column gives you complete control of what to show during display and edit modes.&lt;/p&gt;          &lt;p&gt;Read more about using the Template Column:&lt;/p&gt;          &lt;ul&gt;           &lt;li&gt;&lt;a href="http://blogs.msdn.com/scmorris/archive/2008/03/27/defining-columns-for-a-silverlight-datagrid.aspx#template" target="_blank"&gt;In XAML&lt;/a&gt; &lt;/li&gt;            &lt;li&gt;&lt;a href="http://blogs.msdn.com/scmorris/archive/2008/04/14/defining-silverlight-datagrid-columns-at-runtime.aspx#template" target="_blank"&gt;In Code Behind at Runtime&lt;/a&gt; &lt;/li&gt;         &lt;/ul&gt;       &lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9000390" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/scmorris/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/DataGrid/default.aspx">DataGrid</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/Template+Columns/default.aspx">Template Columns</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/AutoGenerateColumns/default.aspx">AutoGenerateColumns</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/Links/default.aspx">Links</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/Sorting/default.aspx">Sorting</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/Auto-sizing/default.aspx">Auto-sizing</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/Silverlight+2/default.aspx">Silverlight 2</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/Row+Details/default.aspx">Row Details</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/Frozen+Columns/default.aspx">Frozen Columns</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/Column+Resizing/default.aspx">Column Resizing</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/VSM/default.aspx">VSM</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/Column+Reordering/default.aspx">Column Reordering</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/Breaking+Changes/default.aspx">Breaking Changes</category></item><item><title>Sorting Data in the Silverlight DataGrid</title><link>http://blogs.msdn.com/scmorris/archive/2008/06/10/sorting-data-in-the-silverlight-datagrid.aspx</link><pubDate>Tue, 10 Jun 2008 11:11:03 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8589313</guid><dc:creator>scmorris</dc:creator><slash:comments>23</slash:comments><comments>http://blogs.msdn.com/scmorris/comments/8589313.aspx</comments><wfw:commentRss>http://blogs.msdn.com/scmorris/commentrss.aspx?PostID=8589313</wfw:commentRss><description>&lt;table cellspacing="0" cellpadding="5" width="100%" bgcolor="#fff8c9" border="0"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top"&gt;This post has been updated to work with the &lt;a href="http://silverlight.net/GetStarted/" target="_blank"&gt;RTW version of the Silverlight 2 DataGrid&lt;/a&gt;.&amp;#160; The code examples are not guaranteed to work with previous Beta versions of the DataGrid. &lt;a href="http://blogs.msdn.com/scmorris/archive/2008/10/14/silverlight-2-datagrid-is-released.aspx" target="_blank"&gt;Read more about the features that the Silverlight 2 DataGrid has to offer...&lt;/a&gt;&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;h4&gt;Multi-column Sorting&lt;/h4&gt;  &lt;p&gt;One of the most requested features in Beta 1 was a way to sort the data contained in the DataGrid.&amp;#160; In fact it was so desired that clever developers such as &lt;a href="http://mattberseth.com/" target="_blank"&gt;Matt Berseth&lt;/a&gt; simply &lt;a href="http://mattberseth.com/blog/2008/03/sorting_with_silverlight_2s_da.html" target="_blank"&gt;created their own implementation&lt;/a&gt;.&amp;#160; Fortunately, you no longer have to put much work into getting this functionality out of the box.&amp;#160; &lt;/p&gt;  &lt;p&gt;To get sorting functionality in your DataGrid you will need to perform the following steps:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Make sure that the collection that you use as the DataGrid's ItemsSource implements IList.&amp;#160; Common implementations are List&amp;lt;T&amp;gt; and ObservableCollection&amp;lt;T&amp;gt;.&amp;#160; &lt;/li&gt;    &lt;li&gt;That's it, you don't need to do anything else &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Why this odd requirement?&amp;#160; Under the covers, when a DataGrid is data bound to a collection that implements IList, it creates an internal ListCollectionView to provide the sorting functionality.&amp;#160; Since CollectionViews can handle multiple levels of sorting, the DataGrid also possesses this functionality and exposes it by allowing your users to click on multiple headers while holding the Shift key. &lt;/p&gt;  &lt;p&gt;Here is the DataGrid showing off multi-column sorting:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="284" alt="MultiColumnSort" src="http://blogs.msdn.com/blogfiles/scmorris/WindowsLiveWriter/SortingDataintheSilverlightDataGrid_C2F5/MultiColumnSort_f6a82498-f6c9-4f56-b306-a3c8d83b60f9.png" width="484" border="0" /&gt; &lt;/p&gt;  &lt;h4&gt;Customizing Sorting&lt;/h4&gt;  &lt;p&gt;Alternatively if you want more control over how the sorting algorithm is performed, you can implement the ICollectionView interface currently found in System.Windows.Controls.Data.&amp;#160; The DataGrid knows that when it is bound to an implementation of ICollectionView that it should delegate all sorting to it, listening to its SortDescriptions collection and visually displaying the sorting status of the CollectionView.&amp;#160; Additionally by using an external CollectionView, you can have multiple controls share the same sort order.&lt;/p&gt;  &lt;h5&gt;Turning Off Sorting&lt;/h5&gt;  &lt;p&gt;It is easy to get sorting out of the box, but you might not want to allow your DataGrid or a particular column to be sorted by your user.&amp;#160; To turn this off, use DataGrid's CanUserSortColumns property to turn on or off all sorting at the DataGrid level, or use DataGridColumn's CanUserSort to turn on or off sorting for a particular column.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;  &lt;pre class="code"&gt;dataGrid1.CanUserSortColumns = &lt;span style="color: blue"&gt;false&lt;/span&gt;;&lt;/pre&gt;

&lt;pre class="code"&gt;unsortableColumn.CanUserSort = &lt;span style="color: blue"&gt;false&lt;/span&gt;;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&lt;strong&gt;VB&lt;/strong&gt;&lt;/p&gt;

&lt;pre class="code"&gt;DataGrid1.CanUserSortColumns = &lt;span style="color: blue"&gt;False&lt;/span&gt;&lt;/pre&gt;

&lt;pre class="code"&gt;UnsortableColumn.CanUserSort = &lt;span style="color: blue"&gt;False&lt;/span&gt;&lt;/pre&gt;

&lt;h5&gt;Choosing Which Property to Sort By&lt;/h5&gt;

&lt;p&gt;Sometimes the property that your column is bound to is not always the one that you want it to sort by.&amp;#160; Normally a column sorts by the property that it is bound to through the Binding property.&amp;#160; However, if you look at the Template Column there is no Binding property, meaning that the DataGrid has no idea of how to sort the data if you were to click on that column's header.&amp;#160; To give the DataGrid that information, you can use a property found on all column types called SortMemberPath.&amp;#160; This property allows you to specify a path to the property on the data item that you want that particular column to sort by.&amp;#160; Now if you create a template column that uses a DatePicker to allow your user to select a date instead of the standard TextBox, you can still provide sorting for that column by setting the SortMemberPath.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/p&gt;

&lt;pre class="code"&gt;datePickerColumn.SortMemberPath = &lt;span style="color: #a31515"&gt;&amp;quot;Birthday&amp;quot;&lt;/span&gt;;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&lt;strong&gt;VB&lt;/strong&gt;&lt;/p&gt;

&lt;pre class="code"&gt;DatePickerColumn.SortMemberPath = &lt;span style="color: #a31515"&gt;&amp;quot;Birthday&amp;quot;&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;Notice that since SortMemberPath is on DataGridColumn, you can use this beyond just template columns and can actually have a column bound to one property, but sort based on another property.&amp;#160; This is a much less common scenario, but becomes useful when working with types that normally don't support sorting such as Colors or Images.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sorting UI Cues&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In the picture above you can see that each sorted column has an arrow in its header indicating if it is sorted ascending or descending.&amp;#160; It also has a subtle animation when switching between the two.&amp;#160; If you want to customize how this looks or behaves, the easiest way to do this is to use the Visual State Manager in Blend.&amp;#160; Otherwise, you can manually override the &lt;a href="http://msdn.microsoft.com/library/cc278066(vs.95).aspx" target="_blank"&gt;default DataGridColumnHeader template&lt;/a&gt; using the DataGrid.ColumnHeaderStyle property.&amp;#160; The template contains two storyboards, one named &amp;quot;SortAscending&amp;quot; and the other named &amp;quot;SortDescending&amp;quot;.&amp;#160; These two storyboards are ran by the DataGrid when a column is sorted ascending or descending.&amp;#160; Finally there is a third storyboard called &amp;quot;Unsorted&amp;quot; that is ran when the data is no longer being sorted by that column and can be used to clean up any UI that you used to display sort status.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8589313" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/scmorris/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/DataGrid/default.aspx">DataGrid</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/Sorting/default.aspx">Sorting</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/Silverlight+2/default.aspx">Silverlight 2</category></item><item><title>What's New in the Silverlight DataGrid in Beta 2</title><link>http://blogs.msdn.com/scmorris/archive/2008/06/10/what-s-new-in-the-silverlight-datagrid-in-beta-2.aspx</link><pubDate>Tue, 10 Jun 2008 11:07:37 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8589303</guid><dc:creator>scmorris</dc:creator><slash:comments>9</slash:comments><comments>http://blogs.msdn.com/scmorris/comments/8589303.aspx</comments><wfw:commentRss>http://blogs.msdn.com/scmorris/commentrss.aspx?PostID=8589303</wfw:commentRss><description>&lt;p&gt;&lt;a href="http://silverlight.net/GetStarted/" target="_blank"&gt;Silverlight 2 Beta 2&lt;/a&gt; was released this weekend, see what ScottGu has to say about it &lt;a href="http://weblogs.asp.net/scottgu/archive/2008/06/06/silverlight-2-beta2-released.aspx" target="_blank"&gt;here&lt;/a&gt;.&amp;#160; We've all been pretty busy since releasing Beta 1 at MIX, and there are a lot of great new features across the product as a result.&amp;#160; The question that you might be asking is what has changed in the DataGrid?&amp;#160; Check out this list of new features and their associated posts to find out.&lt;/p&gt;  &lt;h4&gt;New Features Overview&lt;/h4&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;&lt;a href="http://blogs.msdn.com/scmorris/archive/2008/06/10/auto-sizing-the-silverlight-datagrid.aspx" target="_blank"&gt;Auto-sizing:&lt;/a&gt;&lt;/strong&gt; Unlike Beta 1 when you had to specify widths and heights yourself, everything in the DataGrid now can be auto-sized.&amp;#160; That includes the DataGrid itself, Columns, Rows, Headers, and Row Details. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;&lt;a href="http://blogs.msdn.com/scmorris/archive/2008/06/10/sorting-data-in-the-silverlight-datagrid.aspx" target="_blank"&gt;Sorting:&lt;/a&gt;&lt;/strong&gt; Now any time you bind the DataGrid to a collection that implements IList such as a List&amp;lt;T&amp;gt; you now get sorting for free.&amp;#160; Even better sorting isn't limited to a single column, but end users can sort by multiple columns by holding Ctrl and clicking on additional column headers. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Column Reordering:&lt;/strong&gt; In Beta 1 the order of columns could be set programmatically, but now in Beta 2 we have extended this capability to the end user, where column reordering can be performed at runtime just by dragging a column's header. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Frozen Columns: &lt;/strong&gt;This is a semi-advanced feature, but once you know about it you'll be surprised at how useful it can be.&amp;#160; A frozen column does not scroll horizontally but rather is &amp;quot;frozen&amp;quot; in place.&amp;#160; This is the same as the Freeze Column feature in Excel. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Programmatic Scrolling: &lt;/strong&gt;Now you can scroll columns and items into view to make sure that an item you want to highlight to your user is visible on screen. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Performance Enhancements:&lt;/strong&gt; One of the big points of feedback we got in Beta 1 was vertical scrolling speed needed to be faster.&amp;#160; We've made some improvements in this space to speed things up. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;API Improvements:&lt;/strong&gt; These are changes that we made to existing API's to try to make using the DataGrid easier.&amp;#160; Hopefully they are all for the better, and we would love to hear your feedback if you think that something could be easier. &lt;/li&gt; &lt;/ul&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8589303" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/scmorris/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/DataGrid/default.aspx">DataGrid</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/Links/default.aspx">Links</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/Sorting/default.aspx">Sorting</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/Beta+2/default.aspx">Beta 2</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/Auto-sizing/default.aspx">Auto-sizing</category><category domain="http://blogs.msdn.com/scmorris/archive/tags/Silverlight+2/default.aspx">Silverlight 2</category></item></channel></rss>