Share via


Freezing Columns in the Silverlight DataGrid

Freezing columns is just one of the many things you can do with the Silverlight DataGrid. Read more about the features that the Silverlight 2 DataGrid has to offer...

Freezing Columns

Have you ever been working with a large enough number of columns that you get horizontal scrolling, but you want some of the columns to not scroll?  Think of a column such as Employee Name that you want to remain visible while you scroll through ten weeks of sales data.  You might want to see which employee had the best sales for week 4.  Since the Employee column is on the far left, any amount of scrolling causes it to scroll out of view, that is unless you freeze it.  This causes it to not scroll and always be visible putting your other data in context.

  FrozenColumns

To freeze columns, you simply set the FrozenColumnCount property on the DataGrid to the number of columns you want to freeze.  For instance, to freeze the Employee column pictured above, you would write:

C#

 employeeSalesGrid.FrozenColumnCount = 1;

VB

 EmployeeSalesGrid.FrozenColumnCount = 1

IsFrozen

If you are programmatically working with a column and want to know if it is frozen or not, you can check the IsFrozen property on the Column.  This is a readonly property that will let you know if the column you are working with is frozen.

Comments

  • Anonymous
    October 14, 2008
    PingBack from http://blogs.msdn.com/scmorris/archive/2008/10/14/silverlight-2-datagrid-is-released.aspx

  • Anonymous
    October 16, 2008
    In this issue: Tim Heuer, Scott Morrison, Corey Schuman, and Jesse Liberty A whole bunch of folks are

  • Anonymous
    October 16, 2008
    could a single column width (like "Week 5") to be fixed so user could not resize it?

  • Anonymous
    October 17, 2008
    Yes, a single column width can be fixed, preventing a user from resizing it, by setting the CanUserResize property on the column to false. ... <DataGridTextColumn Binding="{Binding Week5}" Header="Week 5" CanUserResize="false" /> ... Hope this helps, Scott

  • Anonymous
    October 20, 2008
    Announcements http://weblogs.asp.net/scottgu/archive/2008/10/14/silverlight-2-released.aspx http://www.hanselman.com/blog/Silverlight2IsOut.aspx

  • Anonymous
    November 09, 2008
    Thanks for the nice posts on data grid. I had one more requirement while showing the grid. I want to show the record number (index) as the first column and freeze it so that at any scroll position, you know which index you are on. This will remain same even if some other columns are resorted. Do you have suggestion how we can implement this?

  • Anonymous
    November 24, 2008
    What if I want to Freeze the first column in the grid and the last column?

  • Anonymous
    June 01, 2009
    It seems the DataGrid API is bit short for not providing a way to free columns on the right.  Currently I have to do a whole bunch of calculation to make the columns on the right looked frozen.   Probably this is a feature that should be added.

  • Anonymous
    June 22, 2009
    I would also like to do that, freeze columns to the left and to the right; no ideas?

  • Anonymous
    June 30, 2009
    Thanks for the feedback all.   To clarify your scenarios around freezing the columns to the right.  

  1. Is it only important that the column is always visible and always on the rightmost edge of the DataGrid, or is allowing other columns to scroll, and having them scroll under that frozen column, critical as well?
  2. Does anyone have a scenario where they need to freeze columns on both the left and the right at the same time?  What are you trying to achieve in these scenarios? Thanks, Scott
  • Anonymous
    September 24, 2010
    There could be many scenarios where it could be required, but question is-is thera a way to freeze right side column or not ? It will be great if you can shed some light on it. Thanks

  • Anonymous
    September 24, 2010
    To clarify: there is no way to Freeze a column to the right if you want the others to scroll.   If you just want a column to always be flush right, and horizontal scrolling is not a concern, you can set any of the column widths to its left to star width. Hope this helps. Scott

  • Anonymous
    December 01, 2010
    hi scott We try to follow the drilldown concept of the iphone with a arrow on the right side. So as straight forward we choosed the rowheader to visualize the arrow on the right side. When we have a lot of columns the rowheader will be not visible anymore. So I have to ask again, is there no way to set a right horizontal offest like the datagrid calculates it for the left side depending on the frozencolumncount? Will this feature be available in future releases of the datagrid? thx for help and answering... kind regards dave