Note: This control is not compatible with Visual Studio 11.  A compatible version is available here.


Filter Control is Visual Studio LightSwitch Extension.  This extension will allow users of LightSwitch applications to define custom filters for data that is displayed in a screen.  

Getting Started

To install and use the extension in your LightSwitch applications, unzip the FilterControl zip file into your Visual Studio Projects directory (My Documents\Visual Studio 2010\Projects) and double-click on the FilterControl.vsix package located in the Binaries folder. You only need LightSwitch installed to use the Excel Importer.

In order to build the extension sample code, Visual Studio 2010 Professional, Service Pack 1, the Visual Studio SDK and LightSwitch are required.  Unzip the FilterControl zip file into your Visual Studio Projects directory (My Documents\Visual Studio 2010\Projects) and open the LightSwitchFilter.sln solution.

Building the Sample

To build the sample, make sure that the LightSwitchFilter solution is open and then use the Build | Build Solution menu command.

Running the Sample

To run the sample, navigate to the Vsix\Bin\Debug or the Vsix\Bin\Release folder.  Double click the LightSwitchFilter.Vsix package.  This will install the extension on your machine. 

Create a new LightSwitch application.  Double click on the Properties node underneath the application in Solution Explorer.  Select Extensions and check off LightSwitch Filter Control.  This will enable the extension for your application.

Using the LightSwitch Filter

In your application, define the data you'd like to filter.  For example, create a Table called Customer with a single String property called Name. Right click on the table in solution explorer and select Add Query.  Name the query FilterCustomers.  Add a single string parameter called FilterTerm.

Select the Write Code dropdown for the query and select PreprocessQuery.  Add the following code to the method. 

Visual BasicC#
    query = FilterControl.Filter(query, FilterTerm, Me.Application)

Add a screen based on the query you've defined. Change the control type for the Customer Filter Term control to Advanced Filter Builder.  If you would like the ability to save and load reports, there is an option to do so in the General section of the property sheet. 

Run the application.  The filter builder control should be displayed.  Once you have defined the filter, the Go button will execute it against the server.

How it Works

The filter control will generate an XML representation of the designed filter.  This is then passed to the query as a string.  On the server, the query code will parse the XML and generate appropriate filter clauses. 

For more information on how to develop your own extensions for the community please see the Visual Studio LightSwitch 2011 Extensibility Toolkit. And please ask questions in the LightSwitch Extensibility forum.