Help with lookup values


Author
Message
Sam Garvin
Sam Garvin
StrataFrame Beginner (10 reputation)StrataFrame Beginner (10 reputation)StrataFrame Beginner (10 reputation)StrataFrame Beginner (10 reputation)StrataFrame Beginner (10 reputation)StrataFrame Beginner (10 reputation)StrataFrame Beginner (10 reputation)StrataFrame Beginner (10 reputation)StrataFrame Beginner (10 reputation)
Group: Forum Members
Posts: 10, Visits: 37
Hi

I've been checking the forum and I have found some posts regarding the use of lookup values and now I'm a little bit confused.

I have a maintenance form with some textboxes binded to the fields in BO1, I can navigate, edit, add, delete, etc. and  I've also created a second BO (BO2) and a combobox binded to it and I can see all the descriptions from the table associated to BO2.

What would be the best approach to display the corresponding description (from BO2) instead of displaying the ID value from BO1? I've read about parentrelationship property, about creating a custom property in the BO1 and retrieve the value from table2 in the Fill method in BO1, etc., but so far nothing is working w00t

Any help or advice pointing me in the right direction would be very appreciated.

Thank you very much for your time.

Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Sam,

If you want to show the description in a ListView, you could use a Custom Field Property whit all the binding description so you can use it as a regular field in your list view.  There are a lot of samples in the forum just search for Custom Field Property.

If you are using a combobox to show the lookup data, just define the description field in the lookup to be shown instead of the FK field.  Also you don't need to have a lookup BO for the combobox in the form, just setup the combobox to call a method in your base BO so it will be populated.  The combobox and the listview use an internal BO to get their data and them discard that internal BO.  If for whatever reason you want to have a Lookup BO in the form, then make sure you populate it with the correct data, and use the CopyData method to populate the internal combobox/listview BO.  Check the help file for a better explanation and also search the forums to find many sample code to do this.

Edhy Rijo

Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
Edhy is going down the right path with the custom property if you are going to be binding to a foreign key value from another table.  If you have a foreign key value and want to show the description or title from that table, then you will more than likely just want to create a custom property that calls a scalar method that retrieves the description for display purposes.  Another option would be to create a combo box and use the PopulationDataSource settings.  This is geard for this very thing when dealing with smaller lookup table datasets (200 records or less).  You can create a Fill method on the Foreign Key table BO that just pulls back the PK and the description columns.  Then use an SF combo and populate using a BusinessObject.  You will set the PopulationDataSourceSettings to use the BO of the foreign key value, the Fill method you created to pull back just the PK and the description column, and then set the Display Member to show the description and the Value Member to the foreign key field.  This will setup the very scenario that you are trying to accomplish.
Sam Garvin
Sam Garvin
StrataFrame Beginner (10 reputation)StrataFrame Beginner (10 reputation)StrataFrame Beginner (10 reputation)StrataFrame Beginner (10 reputation)StrataFrame Beginner (10 reputation)StrataFrame Beginner (10 reputation)StrataFrame Beginner (10 reputation)StrataFrame Beginner (10 reputation)StrataFrame Beginner (10 reputation)
Group: Forum Members
Posts: 10, Visits: 37
First of all, thank you Edhy and Trent for helping me.

I added a custom property to my BO and the corresponding field to my select command in the FillAll method and now and can see the description from table2 when navigating through my BO.

       [Browsable(false),
         BusinessFieldDisplayInEditor(),
         Description("F1"),
         DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public System.String F1
        {
            get
            {
                return (System.String)this.CurrentRow["F1"];
            }
        }

and also

      private class Field_F1_Descriptor : MicroFour.StrataFrame.Business.FieldPropertyDescriptor
        {
            public Field_F1_Descriptor() : base("F1") { }
            private System.Type _PropertyType = typeof(System.String);
            public override object GetValue(Object component)
            {
                return ((CBatchFileBO)component).F1;
            }
            public override void SetValue(Object component, object Value)
            {
                //((CBatchFileBO)component).F1 = (System.String)Value;
            }
            public override System.Type PropertyType
            {
                get
                {
                    return this._PropertyType;
                }
            }
            public override System.Type ComponentType
            {
                get
                {
                    return _ComponentType;
                }
            }
        }

Smile

But now I have some other problems: BrowseDialog and Inserting and Editing

First: BrowseDialog

I've been reading some posts and if I understood correctly, I cannot use that custom property field I added in the browsedialog, I tried to use it anyway and I got an error that says: the given key does was not present in the dictionary.

And when trying to browse using other search fields it says that column F1 does not belong to tableX.

I haven't been able to find some examples showing how to do what I need to do ....... so, I'm sorry to keep bothering you guys.

Thanks for your help

Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
Well, first of all, instead of you trying to create a manual FieldPropertyDescriptor, and instead of me dissecting your code, youa re better of in this case overriding the GetCustomBindablePropertyDescriptor and using a ReflectionPropertyDescriptor.  There are a ton of samples on this, including the StrataFlix sample.  So I would recommend downloading the StrataFlix sample so that you can see this in action.

Secondly, you can use the custom property in the results, but not in the search fields, which makes sense...what would it be talking to on the back end?  The search fields are expecting a logical field to query.  Now if you want to capture data from a custom field, then handle the Searching event of the BrowseDialog, you can manipulate the WHERE clause to do whatever you need.

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search