Loop through TypedList (Generic)

Posts   
 
    
JMuller
User
Posts: 19
Joined: 09-Mar-2009
# Posted on: 04-Aug-2009 15:48:11   

Hi,

I have a few TypedLists, and few fields are the same in those typedLists. Now i want to do some calculations on the TypedList, but i don't want to create a new Function for every typed List.

Is there any way i can loop through the base class of a TypedList such as ITypedListLgp2?



public void Calculate(ITypedListLgp2 collection)
{
    foreach (?? in collection)
    {

        }
}


thnx in advance

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 04-Aug-2009 21:13:47   

TypedLists and TypedViews are really just extensions of .Net DataTables, so they have a .Rows collection of .DataRow items.

Matt

JMuller
User
Posts: 19
Joined: 09-Mar-2009
# Posted on: 05-Aug-2009 09:38:22   

Thnx, i got it working, but i hope there's a better way to do this.

Got the following code:



public void Calculate(DataTable collection)
{
  decimal vat = "19.00"

  for (int i = 0; i < collection.Rows.Count; i++ )
  {
     collection.Rows[i][ProductPriceFields.PriceExclBtw.Name] = Convert.ToInt32(priceIncl / (1 + (vat / 100)));
  }
}


But the TypedList rows, are readonly. So for each typedlist, i got to do something like:


TypedList.Columns[ProductPriceFields.PriceExclBtw.Name].ReadOnly = false;

Calculate(TypedList);   

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 05-Aug-2009 11:00:36   

Thnx, i got it working, but i hope there's a better way to do this. Got the following code:

Code:

public void Calculate(DataTable collection) { decimal vat = "19.00"

for (int i = 0; i < collection.Rows.Count; i++ ) { collection.Rows[i][ProductPriceFields.PriceExclBtw.Name] = Convert.ToInt32(priceIncl / (1 + (vat / 100))); } }

That's the only generic way.

But the TypedList rows, are readonly. So for each typedlist, i got to do something like:

Code:

TypedList.Columns[ProductPriceFields.PriceExclBtw.Name].ReadOnly = false;

Calculate(TypedList);

That's by design, as TypedList are ment to be used in a readOnly fashion.