locked
How to manually trigger search function RRS feed

  • Question

  • In my screen I have created a tab control which contains several tables/queries for each tab. To address some performance issues, each of the table has the Auto Execute Query option disabled. I was able to load manually the tables and make the sorting and paging work. However, the built-in search does not function anymore.

    Here is the code snippet of the Screen:

    partial void MyScreen_Activated()
    {
        this.FindControl("children").ControlAvailable += new EventHandler(TabControlAvailableHandler);
    }
     
    void TabControlAvailableHandler(object sender, ControlAvailableEventArgs e)
    {
        TabControl control = e.Control as TabControl;
        control.SelectionChanged += TabControlChangeHandler;
    }
     
    private void TabControlChangeHandler(object sender, SelectionChangedEventArgs e)
    {
        var tab = (TabControl)sender;
        var tabitem = tab.SelectedItem as TabItem;
     
        if (tabitem == null) {
            return;
        }
     
        var cip = tabitem.Content as Microsoft.LightSwitch.Presentation.Framework.ContentItemPresenter;
        if (cip == null) {
            return;
        }
     
        LightSwitchApplication.UserCode.Helpers.LightswitchUiHelper.LoadContentItemValues(cip.ContentItem);
    }

    My friend created a special helper and did the trick in solving the sorting/paging issue.

    Here is the code snippet of the helper:

    ///
    /// Recursively loads the bindings of the content item and its ChildItems.
    ///
    /// The dispatcher.
    /// The content item.
    internal static void LoadContentItemValues(IDispatcher screenDispatcher, IContentItem contentItem)
    {
        foreach (IContentItem tmp in contentItem.ChildItems) 
        {
            LoadContentItemValues(tmp);
        }
    
        if (contentItem.Value != null) 
        {
            LoadMethod(contentItem);
    
            var objectWithDetails = contentItem.Value as Microsoft.LightSwitch.IObjectWithDetails;
            var detailsWithModel = objectWithDetails == null ? null : objectWithDetails.Details as Microsoft.LightSwitch.Details.IDetailsWithModel;
            var contentProperty = detailsWithModel as INotifyPropertyChanged;
    
            if (contentProperty != null) 
            {
                Dispatchers.Main.Invoke(() => {
                    contentProperty.PropertyChanged += (s, e) => {
                        switch (e.PropertyName) 
                        {
                            case "PageNumber":
                            case "SortDescriptors":
                                screenDispatcher.BeginInvoke(() => {
                                    LoadMethod(contentItem);
                                });
                                break;
                        }
                    };
                });
            }
        }
    }
    
    ///
    /// Execute the Load() method of the value.
    ///
    /// The content item.
    static void LoadMethod(IContentItem contentItem)
    {
        if (contentItem.Value != null) 
        {
            var loadmethod = contentItem.Value.GetType().GetMethod("Load");
    
            if (loadmethod != null) 
            {
                loadmethod.Invoke(contentItem.Value, null);
            }
        }
    }

    The problem is I can't get the right solution to make the built-in search function work. Am I missing something here? All possible solution will be very much appreciated. Thanks in advance!

    Regards, 
    Allan Tolentino

    Wednesday, May 29, 2013 8:59 AM

Answers

  • Hey Allan,

    With auto-execute query disabled, you'll want to create your own "Search" query.  It's pretty straightforward to do. Beth Massi has a good walkthrough of this - LightSwitch tips and tricks on query performance

    You can also check out her walkthrough for more details on custom search screens.

    I hope this helps, let me know -Matt Sampson



    R. Matt Sampson

    • Proposed as answer by Angie Xu Thursday, June 6, 2013 1:38 AM
    • Marked as answer by Angie Xu Monday, June 10, 2013 5:43 AM
    Monday, June 3, 2013 3:47 PM
  • Hi Allen,

    There's no need for any special helper method, just call Load on the grid's visual collection.

    So, at whatever point you want the grid to be manually populated, call:

    this.CollectionName.Load();


    Yann Duran
         - Co-Author of Pro Visual Studio LightSwitch 2011
         - Author of the  LightSwitch Central Blog

    FREE Download: Luminous Tools for LightSwitch
    (a Visual Studio productivity extension for LightSwitch)
     
    Click Mark as Answer, if someone's reply answers your question
    Click  Vote as Helpful, if someone's reply is helpful
     
    By doing this you'll help everyone find answers faster.

    Monday, June 3, 2013 6:26 PM
    Moderator

All replies

  • Hey Allan,

    With auto-execute query disabled, you'll want to create your own "Search" query.  It's pretty straightforward to do. Beth Massi has a good walkthrough of this - LightSwitch tips and tricks on query performance

    You can also check out her walkthrough for more details on custom search screens.

    I hope this helps, let me know -Matt Sampson



    R. Matt Sampson

    • Proposed as answer by Angie Xu Thursday, June 6, 2013 1:38 AM
    • Marked as answer by Angie Xu Monday, June 10, 2013 5:43 AM
    Monday, June 3, 2013 3:47 PM
  • Hi Allen,

    There's no need for any special helper method, just call Load on the grid's visual collection.

    So, at whatever point you want the grid to be manually populated, call:

    this.CollectionName.Load();


    Yann Duran
         - Co-Author of Pro Visual Studio LightSwitch 2011
         - Author of the  LightSwitch Central Blog

    FREE Download: Luminous Tools for LightSwitch
    (a Visual Studio productivity extension for LightSwitch)
     
    Click Mark as Answer, if someone's reply answers your question
    Click  Vote as Helpful, if someone's reply is helpful
     
    By doing this you'll help everyone find answers faster.

    Monday, June 3, 2013 6:26 PM
    Moderator