StrataFrame Forum

Iterate through a Buismess Object

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

By Ger Cannoll - 7/27/2010

I am trying to set up a piece of code just to loop through a BO. Took the code below from training class manual but  cant get intellisense on BoType

foreach  (BoType bo in myBo,GetEnumerable() )
{ MessageBox.Show(.....); }
By Edhy Rijo - 7/27/2010

Hi Gerald,



This is something I use a lot Smile Here is the vb version:



For Each record As bizTransactionItems In Me.BizTransactionItems1.GetEnumerable()

record.QBInvoiceRefID = .RefId

record.QBInvoiceNumber = .RefNumber

Next record





Where "record" is the object based on the main class of the business object, not the instance in the form. and Me.BizTransactionItems1 is the instance class in the form. Whatever you do with "record" it is actually happening in Me.BizTransactionItems1 real time, except that GetEnumerable() will keep the record pointer "CurrentRowIndex" updated for you, so don't need to worry about it. w00t



Enjoy!!!!
By Greg McGuffey - 7/27/2010

Edhy right on the money, as usual. Wink



Here is the C# code you might use.



Sample #1: Looping through a BO dropped on a form. Assume you have a BO you've built called MySpecialBO. You've dropped an instance on a form and the instance is named MySpecialBO1.

foreach(MySpecialBO boRow in this.MySpecialBO1.GetEnumerable())

{

  //-- Do something with boRow. Each loop will move it to next row in data table,

  //   only you can use the strongly typed properties to access data.

}




Sample #2: Looping through the BO within the BO itself. We'll use MySpecialBO again, but this time we're doing this inside an instance method.

foreach(MySpecialBO boRow in this.GetEnumerable())

{

  //-- Do something with boRow. Each loop will move it to next row in data table,

  //   only you can use the strongly typed properties to access data.

}
By Ger Cannoll - 7/27/2010

Edhy and greg..many thanks for your replies.

I am getting a ...ideBo1 is a field but is used as a type compile error message. ideBo1 is an instance of the BO on the form and is fine in all other processing.  Must be something very simple but I cant see it ??

foreach (ideBO1 boRow in this.ideBO1.GetEnumerable())
{ MessageBox.Show(ideBO1.IDE_STKREF); }

By Edhy Rijo - 7/27/2010

Hi Gerard,



It should be:



foreach (ideBO boRow in this.ideBO1.GetEnumerable())

{ MessageBox.Show(ideBO1.IDE_STKREF); }
By Ger Cannoll - 7/27/2010

Hi Edhy. Thanks for that. I did not see that is was the Business Object as opposed to the instantiated Business Object that goes with the Foreach. Its compiling now.

regards, Gerard

By Edhy Rijo - 7/28/2010

Hi Gerard,



Glad it is working for you. Tongue



I've been there many times when the .GetEnumerable() was introduced by Trent 2 years ago and I was fairly new to all .Net, but now I use this all over, it is easy, fast and reliable since it will not affect the actual CurrentRowIndex of the BO instance in the form.