Answered by:
Lightswitch Search Not Working

Question
-
Hi,
I've developed a very basic purchase order system. However, the search fails to return any results. I would love to just be able to search by purchase order number which is the main table's primary key. Properties for that field doesn't allow it to be searchable.
There are one to many relationships to this table to facilitate drop downs and purchase order lines.
What do I need to do to allow the primary key to be searchable?
Regards,
Numb
Friday, August 30, 2013 2:25 PM
Answers
-
Hi Numb,
By *default* LightSwitch search boxes only search strings automatically for you. You can definitely create your own query. Here's how:
Create a query on your PurchaseOrder table called PurchaseOrderByID. Add a filter Where ID equals, select parameter, then select Add New to create a new query parameter named Id.
Then add a Search screen, select the PurchaseOrderByID query you created for the screen data. This will set up a picker control for you automatically.
To change it to a TextBox, Add a Data Item to the screen (button at the top of the screen designer) Select Local Property, Type Integer, name it PurchaseOrderID. Drag it onto the screen where you want (this will create a Textbox). Finally data bind the query parameter by selecting the PurchaseOrderByID query in the screen's view model, click the Id query parameter, and in the properties window set the Parameter Binding to the local property PurchaseOrderID.
This post shows how to set up the query for a picker, but like I said you can change it to a Textbox:
http://blogs.msdn.com/b/bethmassi/archive/2013/08/29/how-to-use-a-picker-as-a-filter-in-your-lightswitch-apps.aspxHTH,
-Beth
Senior Program Manager, Visual Studio Community http://www.bethmassi.com http://msdn.com/lightswitch http://dev.office.com
- Proposed as answer by Beth Massi - MicrosoftMicrosoft employee Friday, August 30, 2013 5:01 PM
- Marked as answer by Angie Xu Thursday, September 5, 2013 2:35 AM
Friday, August 30, 2013 5:01 PM
All replies
-
You can only search on strings. If it's an Int, then consider changing it to a string.
Alternatively, make your own search box rather than using the inbuilt grid/list one. You'd have to do the work to link this up to your own query where you'd convert string to int and match on that.
Free Visual Studio LightSwitch extensions: Elyl's Extensions
Friday, August 30, 2013 3:10 PM -
Thank you for the quick response. That's total pants! What was Microsoft thinking of??
Cheers,
Numb
Friday, August 30, 2013 3:16 PM -
Hi Numb,
By *default* LightSwitch search boxes only search strings automatically for you. You can definitely create your own query. Here's how:
Create a query on your PurchaseOrder table called PurchaseOrderByID. Add a filter Where ID equals, select parameter, then select Add New to create a new query parameter named Id.
Then add a Search screen, select the PurchaseOrderByID query you created for the screen data. This will set up a picker control for you automatically.
To change it to a TextBox, Add a Data Item to the screen (button at the top of the screen designer) Select Local Property, Type Integer, name it PurchaseOrderID. Drag it onto the screen where you want (this will create a Textbox). Finally data bind the query parameter by selecting the PurchaseOrderByID query in the screen's view model, click the Id query parameter, and in the properties window set the Parameter Binding to the local property PurchaseOrderID.
This post shows how to set up the query for a picker, but like I said you can change it to a Textbox:
http://blogs.msdn.com/b/bethmassi/archive/2013/08/29/how-to-use-a-picker-as-a-filter-in-your-lightswitch-apps.aspxHTH,
-Beth
Senior Program Manager, Visual Studio Community http://www.bethmassi.com http://msdn.com/lightswitch http://dev.office.com
- Proposed as answer by Beth Massi - MicrosoftMicrosoft employee Friday, August 30, 2013 5:01 PM
- Marked as answer by Angie Xu Thursday, September 5, 2013 2:35 AM
Friday, August 30, 2013 5:01 PM -
Thank you Beth. I will have a go...
All the best,
Numb
Thursday, September 5, 2013 8:45 AM -
Hi Beth,
Got it working a treat. Thank you very much.
All the best,
Numb (as in Comfortably)
Friday, September 6, 2013 4:08 PM