Jinx88909 Jinx88909 - 1 month ago 6
Vb.net Question

Quicker method than looping through thousands of records

Is there a quicker way than looping through thousands of records (around 24k).

This is my code:

For n = 0 To oCHStockItems.Count - 1

Dim itemSellingPrice As New CH.CH_ItemSellingPrice

With itemSellingPrice
.StockItem = oCHStockItems(n).StockItem
.Code = oCHStockItems(n).StockItem.Code
.Name = oCHStockItems(n).StockItem.Name
.ProductGroupCode = oCHStockItems(n).StockItem.ProductGroup.Code
.CurrentSellingPrice = oCHStockItems(n).StockItem.StockItemPrices(0).Price
.NewSellingPrice = 0D
.LastSellingPriceDate = oCHStockItems(n).LastSellingPriceDate
.OriginalPrice = oCHStockItems(n).OriginalPrice
End With

_itemSellingPrices.Add(itemSellingPrice)
Next


Originally I was assigning
oCHStockItems
to a Grid (it's actually a Sage 200 Grid) however I can't seem to find a way to reference to the field
oCHStockItems(n).StockItem.StockItemPrices(0).Price
.

This is my grid

Normally the above kind of syntax works. For example if I want to reference to the Stock Code it would be
StockItem.Code
.

StockItem.StockItemPrices(0).Price
does produce a value however it doesn't show on the Grid. I've logged a ticket with Sage to see if they can help.

However I'm thinking they will come back and say that it can't be done and on that assumption I'm kind of left with looping through
oStockItems
and assigning the properties to the properties of my predefined class. So with that in mind has anyone any suggestions of speeding this kind of process up?

Thanks in advance.

Answer

Sage got back to me with a solution:

First:

AddHandler dgItems.Items.ItemAdded, AddressOf Items_ItemAdded

Then:

Private Sub Items_ItemAdded(ByVal sender As Object, ByVal args As Sage.Common.Controls.ListItemArgs)
    args.Item.SubItems(4).Value = oCHStockItems(args.Item.Index).StockItem.StockItemPrices(0).Price
End Sub

This quickly populates the item on the grid meaning I don't have to loop through thousands of records.

All I have done is assign the original collection oCHStockItems to the .DataSource of the grid and the method Items_ItemAdded sorts the rest out.

Comments