Silverlight 4 Rough Notes: Data Grid Enhancements

Note – these posts are put together after a short time with Silverlight 4 as a way of providing pointers to some of the new features that Silverlight 4 has to offer. I’m posting these from the PDC as Silverlight 4 is announced for the first time so please bear that in mind when working through these posts.

A lot of data is presented in grids and that’s especially true in business applications and so the presence of the DataGrid control in Silverlight is really important.

In Silverlight 4, the DataGrid gets a few enhancements – mostly easy to understand but important to have.

Sizing of DataGrid Columns

When you’re working with a Silverlight 4 DataGrid, you’ll find new options for the Width of a column as the editor shows below;


So we can use settings like “*” settings in order to size header columns and if I’ve got a definition such as;

                    Width="Auto" />
                    Width="*" />
                    Width="3*" />

then that gives me a UI where the 2nd and 3rd columns take up 25% and 75% of the space left after the 1st column is done respectively;


although if I manually as a user then go and change the width of column 2 that’s still allowed and the column doesn’t ignore me.

Being a Better Silverlight 4 Citizen

You should find that the DataGrid does the right thing around things like Copy-Paste and Right-To-Left layout and mousewheel scrolling just as part of being a Silverlight 4 control. As an example, if I walk up to this grid, highlight a bunch of rows and then CTRL-C and CTRL-V into Excel then it does “the right thing”;

image image image

It’s copied to the clipboard as a tab delimited string and you can control what is copied for a particular column by using the DataColumn.ClipboardContentBinding property to point to different data if the cell contents aren’t what you want to have copied ( there’s also a CopyingRowClipboardContent event that you can handle on the DataGrid ).

That’s all I spotted for the beta so far – hopefully I didn’t missing anything ( I’ll update the post if someone tells me that I did 🙂 ).