in
Forums
Blogs
Files
Devexpress.Com
Client Center
Support Center
DevExpress Channel

Lookup and store value rather than Oid

Last post 5/9/2008 9:59 AM by Karl Greenwood. 6 replies.
Page 1 of 1 (7 items)
Sort Posts:
Previous Next
  • 6/30/2007 9:58 AM

    Lookup and store value rather than Oid

    Hi, I've been trying to create a simple lookup that stores a property from a related object, I can do this using two properties, one containing the Oid to the realted object and another storing a string containing the actual value though this is not ideal from the users point of view. Is there any easy way to do this? cheers Karl
    Filed under:
  • 7/4/2007 5:18 AM In reply to

    Re: Lookup and store value rather than Oid

    Hello Karl,
     
    I'm afraid I don't quite understand the behaviour you want to achieve.
    Could you please describe it in more detail?

    --
    Thanks, Dan
    R&D, ..NET Team Developer Express Inc.
     
    PS. If you wish to receive direct assistance from our Support Team, use
    Support Center at http://www.devexpress.com/Support/Center
  • 7/6/2007 9:05 AM In reply to

    Re: Lookup and store value rather than Oid

    hehe, must be my week of this,

    At the moment to get a lookup (combo box) to display I have to use an association. In the database the Oid of the child object is stored in the parent table. I would like to just store a value from the child object not the Oid. It's a standard feature of combo box lookups, what field do you want to store

    The reason, in this case, I want to do this is record data historically, so any changes made to the child table does not affect historical information in the parent table. I managed a workaround by storing the value in another field but it's clunky as hell for the user as they end up seeing two different values for the same thing.

    So a simple lookup that returns the field I want from the chid object is what I'm after, I've tried setting the lookup property on the parent field in the object model to no avail

  • 7/9/2007 10:30 AM In reply to

    Re: Lookup and store value rather than Oid

    Hello Karl,
     
    The scenario you describe looks like a special property editor for string properties which suggests the list of available values (in your case the list is a set of objects of some type). Please let us know if you have difficulties  creating this editor.
    --
    Thanks, Dan
    R&D, .NET Team Developer Express Inc.
     
    PS. If you wish to receive direct assistance from our Support Team, use
    Support Center at http://www.devexpress.com/Support/Center
  • 5/8/2008 9:50 AM In reply to

    Re: Lookup and store value rather than Oid

     

    HI Karl,

    i am having the same problem at this moment. Did you manage to solve the problem? Are there any Code-Snippets out there available?

     

    best regards Uwe

  • 5/9/2008 5:52 AM In reply to

    Re: Lookup and store value rather than Oid

    IMPORTANT SAFETY TIP: This code works for me, but hasn't been extensively tested. Your mileage may vary.

    For this sort of thing, you need to create your own custom property editor that implements a combo box populated with the list of values that you want to choose between. You can then use the model editor to assign this property editor directly to the property that you want to use it for.

    Here is an example of what I did for one of my web projects:

        abstract class WebComboBoxPropertyEditorBase : ASPxPropertyEditor
        {
            protected abstract bool FirstItemIsNull { get; }
            protected abstract Type EditorValueType { get; }
            protected abstract void PopulateEditorItems(ListEditItemCollection items);
            protected virtual object ConvertValueToEditorValue(object value)
            {
                return value;
            }
            protected virtual object ConvertEditorValueToValue(object editorValue)
            {
                return editorValue;
            }
            protected override void SetupControl(WebControl control)
            {
                base.SetupControl(control);
                if (control is ASPxComboBox)
                {
                    ASPxComboBox editor = (ASPxComboBox)control;
                    editor.AutoPostBack = ImmediatePostData;
                    editor.SelectedIndexChanged += new EventHandler(ExtendedEditValueChangedHandler);
                    editor.Items.Clear();
                    editor.ValueType = EditorValueType;
                    PopulateEditorItems(editor.Items);
                }
            }
            protected override WebControl CreateEditModeControlCore()
            {
                return new ASPxComboBox();
            }
            protected override object GetControlValueCore()
            {
                return ConvertEditorValueToValue(Editor.SelectedIndex < (FirstItemIsNull ? 1 : 0) ? null : Editor.SelectedItem.Value);
            }
            protected override void ReadEditModeValueCore()
            {
                object value = ConvertValueToEditorValue(PropertyValue);
                Editor.SelectedIndex =
                    value == null ? (FirstItemIsNull ? 0 : -1) : Editor.Items.FindByValue(value).Index;
            }
            protected override string GetPropertyDisplayValue()
            {
                if (PropertyValue == null)
                    return "";
                else
                    return PropertyValue.ToString();
            }
            public WebComboBoxPropertyEditorBase(Type objectType, DictionaryNode info)
                : base(objectType, info)
            {
            }
            public override void BreakLinksToControl(bool unwireEventsOnly)
            {
                if (Editor != null)
                {
                    Editor.SelectedIndexChanged -= new EventHandler(ExtendedEditValueChangedHandler);
                }
                base.BreakLinksToControl(unwireEventsOnly);
            }
            public new ASPxComboBox Editor
            {
                get { return (ASPxComboBox)base.Editor; }
            }
        }
       
        // We don't want the property editor to be automatically assigned, so don't use this attribute
        //[PropertyEditor(typeof(int))]
        class WebPointsPropertyEditor : WebComboBoxPropertyEditorBase
        {
            protected override bool FirstItemIsNull { get { return true; } }
            protected override Type EditorValueType { get { return typeof(int); } }
            protected override void PopulateEditorItems(ListEditItemCollection items)
            {
                items.Add("", null);
                for (int i = 1; i < 100; i++)
                    items.Add(i.ToString(), i);
            }
            public WebPointsPropertyEditor(Type objectType, DictionaryNode info)
                : base(objectType, info)
            {
            }
        }

     

    Note: to use Enums as values, set the EditorValueType to typeof(int), and override the following two functions:

            protected override object ConvertValueToEditorValue(object value)
            {
                return (int)value;
            }
            protected override object ConvertEditorValueToValue(object editorValue)
            {
                return editorValue == null ? InsertCorrespondingEnumValueHere : (InsertCorrespondingEnumTypeHere)editorValue;
            }

    Something about the combo  box seems to require EditorValueTypes that can be implicitly converted to/from strings and to/from the actual enum type that you want to use.

  • 5/9/2008 9:59 AM In reply to

    Re: Lookup and store value rather than Oid

    No Uwe, I'm waiting for this to be implemented as single property of the lookup combo as even in really simple customer order models you have to store the historical data.

Page 1 of 1 (7 items)
Copyright © 1998-2008 Developer Express Inc.
ALL RIGHTS RESERVED