problem setting value in auto complete box with edit form
-
Tuesday, July 31, 2012 2:00 PM
Hi
I have a form that gets some data from a VIEW in a legacy database. I can't change the structure so there's no way of modifying things to fit better the LS model.
I am using a local property on the form to show a drop down of the data in this legacy data. To complicate matters further this data is filtered in LS on an ID passed into a query built against the view.
I have most of what I need working. When the form loads I can see the drop down with the correct data. I have a save button with the following code in it which works to put the value from the auto complete into the main entity ( co_Consultants_Role):
if (prpWorkFlowRoles != null)
{
co_Consultants_Role.Expertise = prpWorkFlowRoles.WorkflowRole;
}
this.DataWorkspace.EnhesaSQLData.SaveChanges();
this.CloseEditForm();The problem I have is that when the form loads I need the auto complete box to show the data from co_Consultants_Role.Expertise property. i.e. the original data for the property.
But, whatever I try to do in the screen activate event or InitialiseDataWorkspace events the property (prpWorkFlowRoles ) which is the autocomplete box is always null.
if (prpWorkFlowRoles != null){
// code here never gets executed
}
Am I doing something silly? Can anyone suggest what I'm doing wrong? The examples I see all work nicely when the dataset has been built inside LS but whatever i do I cant seem to get it to work in my situation.
thanks
Gus
- Moved by Steve HoagMicrosoft Employee, Moderator Wednesday, August 15, 2012 4:47 AM forum retired (From:LightSwitch in Visual Studio 2012 RC)
All Replies
-
Tuesday, July 31, 2012 2:41 PM
I think the closest I have come is with this in the edit screen InitializeDataWorkSpace.
this.prpWorkFlowRoles = DataWorkspace.EnhesaSQLData.LS_VIEW_WorkFlowRolesSorteds.FirstOrDefault();
But this sets the auto complete box to the first item in the view that populates the control. I want to set it to the current row being edited. How do I get the edit row property in a form that I can use to set the auto complete control?
thanks
Gus
- Edited by GusBeare Tuesday, July 31, 2012 10:24 PM typo
-
Wednesday, August 01, 2012 2:37 PM
solved,
thankfully I got there in the end..
what a palaver though.. I'm starting to feel really old..
the first thing I did at Yann Duran's suggestion was to use a single form for both add and edit based on Beth Massi vid:
http://msdn.microsoft.com/en-us/lightswitch/ff945359
That solved many other issues in one hit. And I got around the drop down problem with this code in the screen Data workspace Initialise.
// get the current expertise value string Exp = this.co_Consultants_Role.Expertise; // set the auto complete control to that value LS_VIEW_WorkFlowRolesSorted wfr = this.DataWorkspace.EnhesaSQLData.LS_VIEW_WorkFlowRolesSorteds.Where(a => a.WorkflowRole==Exp).FirstOrDefault(); if (wfr != null) { this.prpWorkFlowRolesSorted = wfr; }
I needed to add the view itself to the screen and then use that to get a row that matched what is in the entity and then set the auto-complete to that.
This thread got me there:
http://social.msdn.microsoft.com/Forums/en-US/lightswitch/thread/a0d01421-beee-4f04-b23f-36717c83671f/
there must be a simpler way but for now I have something that does the job.
Gus

