How to add calculated column on StockItemLookup Listcolumn?

Hi All,

I have a StockItemLookup and add it to my custom screen.I know how to embed additional columns (see below PKG, Size) from my StockItem extension (I have a table that is an extension from StockItem, called StockItemX).

My question is, can I add column where the value is calculated value of StockItem and StockItemX columns? I must use StockItemLookup, so I cannot make a dropdown box from a view table of StockItem and StockItemX.

  • 0

    You can do this, but you'll need to subclass a couple of things.

    Start off with an extended stock item (and collection).  Here I'm just adding a transient field which calculates a return value from a standard field (Code) and a field in my AddIn table ("MyXTableField"):

       public class ExtendedStockItem : Sage.Accounting.Stock.StockItem
        {
            public const string FIELD_MyTransientField = "MyTransientField";
            protected Sage.ObjectStore.Field _MyTransientField;
    
            [Sage.ObjectStore.Builder.MetaDataField(FieldPropertyName = "_MyTransientField", DbType = System.Data.DbType.Int32,
                IsTransient = true)]
            public int MyTransientField
            {
                get
                {
                    _MyTransientField.ValueRaw = this.Code.Length + this.Fields["MyXTableField"].GetString().Length;
                    return _MyTransientField.GetInt32();
                }
            }
        }
    
        public class ExtendedStockItems : Sage.Accounting.Stock.StockItems
        {
            public override PersistentObject Owner
            {
                get
                {
                    if(this.Query.Owner == null)
                    {
                        this.Query.Owner = new ExtendedStockItem();
                    }
                    return this.Query.Owner;
                }
            }
        }

    Now we'll extend StockItemLookup to add a new column and swap out the data source:

        public class MyStockItemLookup : Sage.MMS.Controls.StockItemLookup
        {
            private Sage.ObjectStore.Controls.ListColumn lengthColumn = null;
    
            protected override void Initialise()
            {
                base.Initialise();
                if (this.Columns.Count == 2)
                {
                    this.lengthColumn = new Sage.ObjectStore.Controls.ListColumn()
                    {
                        Caption = "Length",
                        AutoSize = true,
                        Sortable = false,
                        DisplayMember = "MyTransientField"
                    };
                    this.Columns.Add(lengthColumn);                
                }
                StockItems ds = this.DataSource as StockItems;
                ExtendedStockItems extendedItems = new ExtendedStockItems();
                extendedItems.Query.Filters = ds.Query.Filters;
                this.DataSource = extendedItems;
    
            }

    From that point on it'll behave just like a StockItemLookup (because the Selected events will still treat the extended StockItem as its base type).

  • 0 in reply to Chris Burke

    Hi Chris, it work. but I now I cannot use the StockItemLookup UI/Designer properties. Do I need to override these field as well?

    Edit: Sorry my bad. this screen was for StockLookup. But doing it to StockItemLookup is okay. Now I will do the same to StockLookup