Welcome to MSDN Blogs Sign in | Join | Help

Scott Morrison

The other Microsoft Scott
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.

Posted: Wednesday, October 15, 2008 1:47 AM by scmorris

Comments

Community Blogs said:

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

# October 16, 2008 3:12 PM

unruledboy said:

could a single column width (like "Week 5") to be fixed so user could not resize it?

# October 16, 2008 10:27 PM

scmorris said:

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

# October 17, 2008 1:52 PM

Ram Hegde said:

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?

# November 9, 2008 11:20 PM

Bruce Denham said:

What if I want to Freeze the first column in the grid and the last column?

# November 24, 2008 12:01 PM

De Tran said:

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.

# June 1, 2009 7:59 PM

ledz said:

I would also like to do that, freeze columns to the left and to the right; no ideas?

# June 23, 2009 6:36 AM

scmorris said:

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

# June 30, 2009 2:22 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

  
Enter Code Here: Required

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Page view tracker