Sunday, February 27, 2011

A Example of _BeforeDataInitialize for Microsoft Lightswitch Collections

When you have a Lightswitch edit screen, its not clear from the doc what
you need to do to init data. You have to create a instance of the item,
and put it into the collections selected item field.
Like So.

partial void PurchaseRequests_BeforeDataInitialize()
{
// Write your code here.
PurchaseRequest theitem = new Portal.PurchaseRequest();
theitem.PrState = "Unsubmitted";
theitem.Requestor = Application.Current.User.Name;
theitem.Subtotal = 0;
theitem.Total = 0;
theitem.CurrentcyType = "SGD";
theitem.DateCreated = DateTime.Now;
theitem.DateUpdated = DateTime.Now;
PurchaseRequestCollection.SelectedItem = theitem;
}
}

0 comments: