locked
Clear the DataGrid search box programmatically RRS feed

  • Question

  • Hi All,

    I am creating a custom search screen (Silverlight client) for my users where they have several options like date ranges and a few checkboxes, dropdowns, etc. to find what they need. In addition, they can search through the returned data using the default search box that the LightSwitch grid provides.

    I have given a "clear" button on this screen that goes and resets all the search fields to their default values. But I am not able to clear the search keywords typed in the search  box on the grid. Is there any way to do this from the code (C#)? I understand that the users could click the "x" in the searchbox and clear the text, but they would prefer it if they had to click just once to clear everthing.

    Thanks in advance!!

    Jayesh

    Wednesday, May 1, 2013 6:41 PM

Answers

  • Here's some sample code to do this:

    IScreenCollectionPropertyLoader loader = (IScreenCollectionPropertyLoader)this.Details.Properties.Customers.Loader;
    loader.SetSearchTerms(Enumerable.Empty<SearchTerm>());

    Change "Customers" to the name of the collection property to which your data grid is bound.

    Justin Anderson, LightSwitch Development Team

    • Marked as answer by JayeshK Thursday, May 2, 2013 3:32 PM
    Thursday, May 2, 2013 3:08 AM
    Moderator

All replies

  • Jayesh,

    Why not remove the standard search box and create your own?  On your existing query, add another string parameter, mark it as optional, and set your where statement(s) as you see necessary.  This way, you can control the search and not have to tap into the core search control.

    Just a suggestion.

    Brian


    Brian

    Wednesday, May 1, 2013 7:49 PM
  • Here's some sample code to do this:

    IScreenCollectionPropertyLoader loader = (IScreenCollectionPropertyLoader)this.Details.Properties.Customers.Loader;
    loader.SetSearchTerms(Enumerable.Empty<SearchTerm>());

    Change "Customers" to the name of the collection property to which your data grid is bound.

    Justin Anderson, LightSwitch Development Team

    • Marked as answer by JayeshK Thursday, May 2, 2013 3:32 PM
    Thursday, May 2, 2013 3:08 AM
    Moderator
  • @Justin: Thanks a lot! Your sample code is perfect for what I need!

    @Brian: Thanks for your suggestion. My result set has quite a few columns, so I believe that the resultant query might not be very efficient ( lots of OR conditions ). Also, I like that the default search box shows the "Search" watermark and I'm not sure how I would do that in my own search box ( maybe this would need an extension or a custom control? ). But Justin's response (above) fits perfectly!

    Thanks!

    Thursday, May 2, 2013 3:32 PM
  • Please could you explain a little more what the types and methods in that code are, and what the code actually does? These sorts of snippets are vital to getting a deeper understanding of Lightswitch.

    If there is any documentation on this, please point it out.

    Thanks very much.


    FREE custom controls for Lightswitch! A collection of useful controls for Lightswitch developers. Download from the Visual Studio Gallery.

    If you're really bored, you could read about my experiments with .NET and some of Microsoft's newer technologies at http://dotnetwhatnot.pixata.co.uk/

    Friday, May 3, 2013 3:04 PM