How to calculate the screen child datagrid totals in Microsoft Lightswitch?

There are two ways to calculate the screen child datagrid totals.

  1. Directly access the workspace data from the screen child datagrid.
  2. Use the existing data in screen child datagrid.

Now which method of calculating the totals in the screen child datagrid would you choose? My answer is, it depends on the requirement of the client.

To directly access the workspace data from the screen child datagrid you need to follow the three steps.

  1. Create a workspace object
  2. Get the query of the child datagrid
  3. Loop through the query to compute for the total

Here is the sample code snippet:

Dim ws = Me.Application.CreateDataWorkspace()
Dim rs= ws.ApplicationData.MyDataGrid.GetQuery().Execute()
Dim records= From r In rs

For Each record In records
    Total = Total + record.Amount
Next

To use the existing data in the screen child datagrid you need to follow the following steps:

1. Remove the paging of the data in the datagrid

2. Loop through the datagrid data to compute for the total

Thats it, the problem in method no. 2 is that you need to remove the paging support before you could loop through the data otherwise you can only calculate the data of the current page.

Below is an actual application example that uses method no. 2 in calculating the screen child data grid, of course I already added the screen data so that the result can be displayed in the screen.

Advertisements
About

Software developer living in the Philippines.

Posted in Lightswitch
2 comments on “How to calculate the screen child datagrid totals in Microsoft Lightswitch?
  1. Exists a way to Refresh the number of, for example “Total Debit Amount:”, when you used the Search to filter the data what you need?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Author

Harold Glenn P. Minerva
Software Developer / Tech Enthusiast
Living in the Philippines

View Harold Glenn Minerva's profile on LinkedIn

Instagram

Software Engineer - Seasonal and Range Trading Software. Magenta Trader is a powerful stock market visualization software that increases your probability of trading success.

Software Architect and Founder - Easyfis.com is a multi-tenant cloud-based Software-as-a-Service (SaaS) business app that caters to micro, small and medium trading businesses.

CTO and Co-Founder - We give your company the leverage by providing innovative software solutions products such as Point-of-Sales (POS), Financial Information System (FMIS), Payroll and DTR (HRIS), and many more.

%d bloggers like this: