Jinx88909 Jinx88909 - 1 year ago 71
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


Originally I was assigning
to a Grid (it's actually a Sage 200 Grid) however I can't seem to find a way to reference to the field

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

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
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 Source

Sage got back to me with a solution:


AddHandler dgItems.Items.ItemAdded, AddressOf Items_ItemAdded


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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download