Finding what you need in the Microsoft� Visual Studio� documentation, which has over 200,000 topics, can be a daunting task. The Doc Detective is here to help, utilizing his investigative skills to probe the depths of the documentation.

Can't find what you're looking for? Just ask - if it's in there, I'll find it for you; if it isn't, I'll let you know that as well (and tell you where else you might go to find it).

Have a question for the Doc? Send your questions for future columns to me at docdetec@microsoft.com.

Dear Doc Detective,

I'm writing an order entry application in Visual Studio LightSwitch, and my users are asking for better feedback when an order is saved. I would like to add a message telling them that the order was successfully saved and also to remind them to update the order tracking Excel spreadsheet. Any ideas?

  • Saved in Sarasota

Dear Saved,

I have plenty of ideas, most not fit for publication. As for providing feedback, you can add code in the _Saved method for your screen to display a message box:

Private Sub OrdersScreen_Saved()
ShowMessageBox("Order was saved. Don't
forget to update the order tracking
spreadsheet!")
End Sub

You can do pretty much anything you want in the Saved method - for example, instead of reminding the user to update the spreadsheet you could use COM automation to update the spreadsheet for them.

The Saved method is described in the topic “How to: Add, Remove, or Modify Commands for a Screen.” You might also be interested in the Saving method which occurs before the changes are committed, and the SaveError method which occurs when changes can't be saved.

  • the Doc

Dear Doc Detective,

In my LightSwitch application I have a screen that displays customers. I would like to limit the display to only customers that have not been contacted in the past six months.

I've played around with the Query designer, but it seems fairly limited in its capabilities and I can't find a way to do this. Surely LightSwitch isn't that limiting - or is it?

  • Limited in Linville

Dear Limited,

Although the Query designer is fairly limited in terms of the types of queries you can create, you can always write code to extend a query.

LightSwitch supports LINQ syntax, so any query that can be defined using LINQ can be used to define the data that will be displayed on a screen. The topic “How to: Extend a Query by Using Code” shows several examples of using LINQ to - you guessed it - extend a query.

  • Doctor D

Dear Doc Detective,

I saw your answer on LightSwitch authentication and authorization in your last column. I followed the instructions in the referenced topic and it works like a charm - so far, so good.

There is one thing that I can't figure out, though. I can create users and roles in my published application, but how do I impersonate a user at design time for testing purposes?

  • Rolling in Rollag

Dear Rolling,

It's always rewarding to see that someone really does read this column. The answer is, you can't - well, not exactly.

While you can't log on as a different user, you can set debug permissions at design time, which essentially does the same thing. On the Access Control tab of the Application designer, check the “Granted for debug” checkbox for each permission that you have defined for a particular user or role. When you run the app, you will have the same access that your user will have in the published app.

This is demonstrated in the “Using Debug Permissions to Test Code” lesson in the “LightSwitch Guided Tour” tutorial.

  • the Doc

Dear Doc Detective,

I have a question. I would like to get a count of the records returned by my LightSwitch query and display them on my screen. How would I do that?

  • Questioning in Queens

Dear Questioning,

To your one question I have a two-part answer. To get a count, create a query and extend it using LINQ to return a count. You can then get the count by calling the Execute method of the resulting query:

Dim recordCount As Integer

recordCount = Me.DataWorkspace.DataSourceName.
MyQueryName.Execute().Count

You may wonder why you need to execute the query instead of simply returning the Count property of the Query object. The Count property returns the query collection associated with the screen, and if you have more than one page of data it will return the count only for the first page.

To display the count on your screen, you can add a label as shown in the topic “How to: Add a Local Field to a Screen” and assign recordCount as its value.

  • the Doc

Doc's Doc Tip of the Day

Frustrated with the new Help viewer in Visual Studio 2010? You're not alone. Fortunately relief is coming in Visual Studio 2010 SP1, with a number of usability improvements.

You can read all about them in Jeff Braaten's blog "The Story of Help in Visual Studio 2010 (Part 3)".

Found a topic in Help that doesn't help? Tell the Visual Studio documentation team about it by clicking on the “Send feedback” link in local Help topics, or the “Click to rate and give feedback” link in online Help.

URLs