Welcome to LightSwitch Desktop Edition > FlexGrid for LightSwitch Overview > Programming FlexGrid for LightSwitch > Customizing the C1FlexGrid Control |
To view the code-behind for a LightSwitch screen, click Write Code on the designer toolbar. Note that you can only access the runtime Silverlight components via a proxy. Typically, this is done in the screen’s Created method as shown in the following example:
partial void Test_Created() { IContentItemProxy proxy = this.FindControl("C1FlexGrid"); proxy.ControlAvailable += new EventHandler<ControlAvailableEventArgs>(proxy_ControlAvailable); }
The FindControl method takes the name of the control (not the display name) and returns an object that supports the IContentItemProxy interface. For a FlexGrid Screen, the name C1FlexGrid is given to the one-and-only C1FlexGrid control. Note that if you were to modify the name of this control in the designer, you would also have to modify the name used in code.
When the LightSwitch runtime has finished creating the control you specified in the call to FindControl, the ControlAvailable event will fire, and you will access the control within the handler for that event. But first, in order to refer to ComponentOne objects and access their properties, methods, and events, you will need to add references to the underlying Silverlight assemblies. On the Project menu, click Add Reference, and then click the Browse tab. Look in the following folder, relative to the LightSwitch project file (.lsproj):
_Pvt_Extensions\C1.LightSwitch.FlexGrid\ClientGen\Reference
Scroll down to the bottom of the list and select the following assemblies:
Click OK to close the Add Reference dialog. Next, add the following using statement to your code:
using C1.Silverlight.FlexGrid;
Now you can reference the C1FlexGrid control within the ControlAvailable event handler and cast it to the appropriate type:
C1.Silverlight.FlexGrid.C1FlexGrid _flex; void pageProxy_ControlAvailable(object sender, ControlAvailableEventArgs e) { _flex = e.Control as C1.Silverlight.FlexGrid.C1FlexGrid; }
For convenience, you can save the C1FlexGrid control to a member variable within the screen class, as in the preceding example, making it available to other methods. Once you have access to the grid control, you can customize its properties. For example, the following code makes the first two grid columns nonscrolling:
_flex.FrozenColumns = 2;