Reputation: 205
I am trying to set a default value for a multi-valued parameter in Lightswitch but am having no luck.
For an example, I have a hardware inventory. "Hardware" table has fields of ('active', bool) and ('company_id',int). Company_id is a foreign key to a Company table which contains a list of companies to select from.
I want to filter my Lightswitch screen based on these two field, but when the screen first loads I want it to default to the primary company, for active hardware.
I have created the Local Property for my 'active' parameter, added it to the screen. Setting up the dropdown list for company parameter requires:
I then specified the default values as such in code:
partial void Screen1_Created()
{
// Write your code here.
SelectedCompanies.company_id = 2;
selected_active_property = true;
}
This works just fine for the 'active' parameter which is Boolean, however the SelectedCompanies line gives an intellisense error of:
Property or indexer "LightswitchApplication.company.company_id" cannot be assigned to -- it is read only
Has anyone gotten a default value for this type of parameter working before?
Upvotes: 1
Views: 5122
Reputation: 3879
In LightSwitch, you can't set foreign keys directly. You have to retrieve the entity from the table, & assign that entity to the entity property.
So, in your case it would be:
partial void Screen1_Created()
{
SelectedCompany = this.DataWorkspace.ApplicationData.Companies_SingleOrDefault(2);
selected_active_property = true;
}
Upvotes: 5