The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
|
|
Lookup and binding primary key and string values
Posted: 17 Mar 09 1:39 PM
|
I have a lookup that I want to bind the string resulting value to a text text field and it's corresponding primary id to an id field. I already have the "lookup resulting value" bound to the text field. How do get the primarykey to bind to the id field I have created? |
|
|
|
Re: Lookup and binding primary key and string values
Posted: 18 Mar 09 4:21 AM
|
Hi Andrew
You'll have to forgive me, I'm still a bit of a novice to this too, but I reckon the best way would be to change the Lookup to return the primary key and then change the binding to your ID field.
Next set an onChange event for the Lookup. Using the resultant ID get the Text that you want and insert that into the field you want.
Note: It is best to set your result into the entity property, rather than a control, as this is less prone to problems.
If you need any further help with this post a reply and I'll help if I can - but I'm sure one of the other SLX masters will be able to help! 
David |
|
|
|
Re: Lookup and binding primary key and string values
Posted: 18 Mar 09 4:18 PM
|
Andrew, Here's how I'd go about it:
- Make a lookup that's a button only - Be sure that the Lookup Biding Mode (about 1/2 way down in the properties window) is set to 'Object' - In the on change event of the lookup, bind to the entity and then assign values as you see fit. For example: Sage.Entity.Interfaces.IMyEntity me = lueLookup.LookupResultValue as Sage.Entity.Interfaces.IMyEntity;
Now, you can get all fields in the entity you just returned using standard entity properties (me.Id, me.MyField, etc...)
I've used this technique before for various reasons. If you want it to look right, you may want to put one of the text fields in a control container next to the lookup control. This makes it appear as a stock lookup to the user. Mike LaSpina |
|
|
| |
|
Re: Lookup and binding primary key and string values
Posted: 19 Mar 09 3:35 PM
|
I have a similar issue where my lookup is to filter a grid based on what is selected. I have a business rule that uses GetByMethod to return an IList that is tied to the grid, but this only works if I open a form that has that lookup value already populated.
So how do I do something similar to your example to refresh\reset the datasource or whatever I need to do to make the grid refresh with the item selected in the lookup? “Sage.Entity.Interfaces.IMyEntity me = lueLookup.LookupResultValue as Sage.Entity.Interfaces.IMyEntity;”
Btw when I try something like this on the change actions of the lookup it blows up on creating the repository. This came from my business rule that works for existing records. No I also need it dynamically filter the grid at runtime. -------------- IRepository repository = EntityFactory.GetRepository(); IQueryable qry = (IQueryable)repository; IExpressionFactory ef = qry.GetExpressionFactory(); ICriteria criteria = qry.CreateCriteria(); criteria.Add(ef.Eq("Templateheaderid", bidspec.Template.ToString())); result = criteria.List();
|
|
|
|
Re: Lookup and binding primary key and string values
Posted: 20 Mar 09 7:29 PM
|
Ken & Co.
Got it to work! Thanks for everyone's help!
Here was my final solution (On Change Action: C# Snippet Action Item):
Sage.Entity.Interfaces.ICAccountAgencyLink CAccountAgencyLink = this.BindingSource.Current as Sage.Entity.Interfaces.ICAccountAgencyLink;
Sage.Entity.Interfaces.IContact contact = lkpAgencyContact.LookupResultValue as Sage.Entity.Interfaces.IContact;
CAccountAgencyLink.AgencyContactID = contact.Id.ToString(); CAccountAgencyLink.AgencyContact = contact.FullName;
|
|
|
|