StrataFrame Forum

Accessing BO data Via BusinessBindingSource

http://forum.strataframe.net/Topic32743.aspx

By Bruno J Rondolat - 11/13/2014

Forgive the lack of poor code my C# skills are very limited.

Currently sharing a large BusinessBindingSource.  This allow me to load the data once and then use it on diverse forms without having to reload the data on each form.  The underlying data is mostly static so this works very well.  

Currently using the following method to share the data .

Form1

  Form2.SharedBusinessSourceProducts = _sharedBusinessSourceProducts;
  Form2.ShowDialog();

Form2

        private BusinessBindingSource _sharedBusinessSourceProducts;
        public BusinessBindingSource SharedBusinessSourceProducts
        {
            get
            {
                return _sharedBusinessSourceProducts;
            }
            set
            {
                _sharedBusinessSourceProducts = value;
            }
        }


when I access the data in form2 I use (their must be a nicer way BigGrin )

// move to correct row
_sharedBusinessSourceProducts.BusinessObject.SeekToPrimaryKey(productID);
// get column of field QtyInBundle
 int QtyInBundleidx = _sharedBusinessSourceProducts.BusinessObject.CurrentRow.Table.Columns.IndexOf("QtyInBundle");
// get value
qtyInBundle = (Int32)_sharedBusinessSourceProducts.BusinessObject.CurrentRow.ItemArray[QtyInBundleidx];

isn't their a way I could just access the field name directly and do something like (assuming that the base BO is called BaseProductsBO)

qtyInBundle = _sharedBusinessSourceProducts.BaseProductsBO.QtyInBundle;

Basically I would like to bypass the whole getting the index of the field and just use the "typical"  access via the BO. 

I used to used the BO directly and have a shared SharedDataTableKey set but this caused some performance issues used a lot more memory and strangely not all of the memory would get returned after the form disposal. 

By Ivan George Borges - 11/13/2014

Hi Bruno.

Try:

qtyInBundle = DirectCast(_sharedBusinessSourceProducts.BusinessObject, YourBOName).QtyInBundle;
By Bruno J Rondolat - 1/22/2015

Thanks for your help.  You pointed me in the correct direction.  The solution in C# was to do the following.

string QtyInBundle= ((YourBOName)_sharedBusinessSourceProducts.BusinessObject).QtyInBundle;
By Ivan George Borges - 1/23/2015

Glad it helped! Cool

And sorry for posting in VB.NET. I should have noticed your sample in C#.