Freeze panes in a standard LightSwitch datagrid.

Introduction

Freezing panes in a standard silverlight datagrid is very easy. Simply set dataGrid.FrozenColumnCount = x, where x is the number of columns you want to freeze.

You can easily do the same in LightSwitch by means of the following extension method:

    public static class DataGridExensions
    {
        public static void FreezeColumns(this IContentItemProxy proxy, int amountOfColumnsToFreeze)
        {
            proxy.ControlAvailable += new EventHandler<ControlAvailableEventArgs>((s1, e1) =>
            {
                DataGrid dataGrid = e1.Control as DataGrid;
                dataGrid.FrozenColumnCount = amountOfColumnsToFreeze;
            });
        }
    }

Calling the extension method is best done in the _created event of the screen:

partial void SearchCustomers_Created()
        {
            IContentItemProxy proxy = this.FindControl("grid");
            proxy.FreezeColumns(2);
        }
    }

Simple but very much appreciated by your customers, isn't it?