locked
GridView with SearchBox column

    Question

  • Can a column of a GridView be a SearchBox?
    Wednesday, January 28, 2015 11:37 AM

Answers

  • Hi FSL_AU,

    Have you tried to use SearchBox in GridView control? I tried to put SearchBox control to replace the ComboBox in GridView, it worked well. I modified the code based on this MSDN sample. https://code.msdn.microsoft.com/windowsapps/SearchBox-control-sample-0f64f94d. See details in Scenario 1.

    Steps to reproduce.

    1. Create a new GridView.
    2. Override its ItemTemplate.
    3. Copy SearchBox XAML into date template.
    4. Bind datasource to GridView
    5. Run your project.
    <GridView x:Name="gridview1" HorizontalAlignment="Left" Margin="385,10,-185,0" VerticalAlignment="Top" Width="100">
    
                        <GridView.ItemTemplate>
    
                            <DataTemplate>
    
                                <StackPanel>
    
                                    <SearchBox x:Name="SearchBoxSuggestions" Height="35" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" SuggestionsRequested="SearchBoxEventsSuggestionsRequested" QuerySubmitted="SearchBoxEventsQuerySubmitted"/>
    
                                    <TextBox Text="{Binding Name}"></TextBox>
    
                                </StackPanel>
    
                            </DataTemplate>
    
                        </GridView.ItemTemplate>
    
                    </GridView>
    

    • Marked as answer by FSL AU Monday, February 9, 2015 8:27 AM
    Monday, February 9, 2015 7:04 AM

All replies

  • Yes.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Wednesday, January 28, 2015 4:17 PM
    Moderator
  • Thank you Matt. Are you able to help me with a simple example of the markup? We are considering developing a Windows Store app. Our GridView would have a ProductId SearchBox which would search a list of ProductIds created as below

    public class Products
    {
        public class Product
        {
            public Int64 ProductId { get; set; }
        }

            public List<Product> theList { get; set; }

            public Products()
            {
                theList = new List<Product>();
               // populate theList of products

             }

    }

    On the Prodcuts form we envisage something like

    Products products = new Products();
    ProductsSearchBox.ItemsSource = products.theList;

    Wednesday, January 28, 2015 7:34 PM
  • I dont really understand the workflow here.  It's trivial to put a series of SearchBoxes into a GridView, but I'm not sure what your desired outcome is.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Thursday, January 29, 2015 6:43 PM
    Moderator
  • The user is creating an order. An order is a collection of products.

    The objective is to search a list of ProductIds from a SearchBox column in a GridVeiw.

    The user should be able to type a product id into the searchbox column of the gridview and that searchbox column search the products list for that product id.

    The user would then type another ProductId into the SearchBox column of the next row of the GridView to select another Productid.

    We currently do this with a DataGrid with a ComboBox column. We want to make sure we can do this with a GridView/SearchBox column before porting our app to Windows Store.

    • Edited by FSL AU Saturday, January 31, 2015 9:15 PM typo
    Thursday, January 29, 2015 7:48 PM
  • Hi FSL_AU,

    Have you tried to use SearchBox in GridView control? I tried to put SearchBox control to replace the ComboBox in GridView, it worked well. I modified the code based on this MSDN sample. https://code.msdn.microsoft.com/windowsapps/SearchBox-control-sample-0f64f94d. See details in Scenario 1.

    Steps to reproduce.

    1. Create a new GridView.
    2. Override its ItemTemplate.
    3. Copy SearchBox XAML into date template.
    4. Bind datasource to GridView
    5. Run your project.
    <GridView x:Name="gridview1" HorizontalAlignment="Left" Margin="385,10,-185,0" VerticalAlignment="Top" Width="100">
    
                        <GridView.ItemTemplate>
    
                            <DataTemplate>
    
                                <StackPanel>
    
                                    <SearchBox x:Name="SearchBoxSuggestions" Height="35" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" SuggestionsRequested="SearchBoxEventsSuggestionsRequested" QuerySubmitted="SearchBoxEventsQuerySubmitted"/>
    
                                    <TextBox Text="{Binding Name}"></TextBox>
    
                                </StackPanel>
    
                            </DataTemplate>
    
                        </GridView.ItemTemplate>
    
                    </GridView>
    

    • Marked as answer by FSL AU Monday, February 9, 2015 8:27 AM
    Monday, February 9, 2015 7:04 AM