Adding LightSwitch Buttons

In the screen designer, select the Screen Command Bar element and add seven buttons with the following names:

If desired, you can modify the button display names, add description strings, and specify images. But the names should be entered exactly as above in order for the following code to work. Since we already have code that sets up an OLAP view given a field name to use for rows, it is trivial to wire up the ViewBy buttons:

C#
Copy Code
partial void ViewByCountry_Execute()
{
    ViewBy("Country");
}

partial void ViewByProduct_Execute()
{
    ViewBy("ProductName");
}

partial void ViewBySalesPerson_Execute()
{
    ViewBy("Salesperson");
}

Since the built-in LightSwitch buttons don’t support a “pressed” state, we’ll fake it by disabling the button that represents the current view. That way, the user will have some visual indication as to which view is current, and we’ll avoid the situation where the user clicks a button and nothing happens because that view is already the current one. To do this, append the following lines to the end of the existing BuildView method:

C#
Copy Code
// enable view buttons
this.FindControl("ViewByCountry").IsEnabled = (fieldName != "Country");
this.FindControl("ViewByProduct").IsEnabled = (fieldName != "ProductName");
this.FindControl("ViewBySalesPerson").IsEnabled = (fieldName != "Salesperson");

This code ensures that all view buttons are enabled except for the currently selected one, both at start-up and whenever the user clicks a button.

 

 


Copyright (c) GrapeCity, inc. All rights reserved.

Product Support Forum  |  Documentation Feedback