Looping through a datagrid

DekaFlash

Well-known member
Joined
Feb 14, 2006
Messages
117
Programming Experience
1-3
I am trying to figure out how to update the existing rows rather then wiping the table and then recreating it on each refresh.

I would appreciate some assistnace with the correct syntax please.

Thanks

VB.NET:
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] (CurrentMarket.marketId > 0) [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]tbl.Rows.Clear()
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] total [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Decimal
[/COLOR][/SIZE][SIZE=2]total = 0
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] req [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] GetMarketPricesReq
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] resp [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] GetMarketPricesResp
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] r [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] DataRow
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] s [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] DataRow
req.header = Header
req.marketId = CurrentMarket.marketId
resp = BFService.getMarketPrices(req)
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] i [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] j [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer
[/COLOR][/SIZE][SIZE=2]TextBox14.Text = CurrentMarket.runners.Length
[/SIZE][SIZE=2][COLOR=#0000ff]For[/COLOR][/SIZE][SIZE=2] i = 1 [/SIZE][SIZE=2][COLOR=#0000ff]To[/COLOR][/SIZE][SIZE=2] CurrentMarket.runners.Length
r = tbl.NewRow
r("Name") = CurrentMarket.runners(i - 1).name
[/SIZE][SIZE=2][COLOR=#0000ff]For[/COLOR][/SIZE][SIZE=2] j = 1 [/SIZE][SIZE=2][COLOR=#0000ff]To[/COLOR][/SIZE][SIZE=2] resp.marketPrices.runnerPrices.Length
[/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] (resp.marketPrices.runnerPrices(j - 1).selectionId = CurrentMarket.runners(i - 1).selectionId) [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] (resp.marketPrices.runnerPrices(j - 1).bestPricesToBack.Length = 1) [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]r("Back 3") = 0
r("Back 2") = 0
r("Back 1") = resp.marketPrices.runnerPrices(j - 1).bestPricesToBack(0).price [/SIZE][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]ElseIf[/COLOR][/SIZE][SIZE=2] (resp.marketPrices.runnerPrices(j - 1).bestPricesToBack.Length = 2) [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]r("Back 3") = 0
r("Back 2") = resp.marketPrices.runnerPrices(j - 1).bestPricesToBack(1).price [/SIZE][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][SIZE=2]r("Back 1 ") = resp.marketPrices.runnerPrices(j - 1).bestPricesToBack(0).price[/SIZE][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]ElseIf[/COLOR][/SIZE][SIZE=2] (resp.marketPrices.runnerPrices(j - 1).bestPricesToBack.Length = 3) [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]r("Back 3") = resp.marketPrices.runnerPrices(j - 1).bestPricesToBack(2).price [/SIZE][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][SIZE=2]r("Back 2") = resp.marketPrices.runnerPrices(j - 1).bestPricesToBack(1).price [/SIZE][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][SIZE=2]r("Back 1") = resp.marketPrices.runnerPrices(j - 1).bestPricesToBack(0).price [/SIZE][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Else
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]' Do Nothing
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] (resp.marketPrices.runnerPrices(j - 1).bestPricesToLay.Length = 1) [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]r("Lay 3") = 0
r("Lay 2") = 0
r("Lay 1") = resp.marketPrices.runnerPrices(j - 1).bestPricesToLay(0).price [/SIZE][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]ElseIf[/COLOR][/SIZE][SIZE=2] (resp.marketPrices.runnerPrices(j - 1).bestPricesToBack.Length = 2) [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]r("Lay 3") = 0
r("Lay 2") = resp.marketPrices.runnerPrices(j - 1).bestPricesToLay(1).price [/SIZE][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][SIZE=2]r("Lay 1") = resp.marketPrices.runnerPrices(j - 1).bestPricesToLay(0).price [/SIZE][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]ElseIf[/COLOR][/SIZE][SIZE=2] (resp.marketPrices.runnerPrices(j - 1).bestPricesToBack.Length = 3) [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]r("Lay 3") = resp.marketPrices.runnerPrices(j - 1).bestPricesToLay(2).price [/SIZE][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][SIZE=2]r("Lay 2") = resp.marketPrices.runnerPrices(j - 1).bestPricesToLay(1).price [/SIZE][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][SIZE=2]r("Lay 1") = resp.marketPrices.runnerPrices(j - 1).bestPricesToLay(0).price [/SIZE][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Else
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]' Do Nothing
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][COLOR=#008000][/COLOR][/SIZE][SIZE=2]tbl.Rows.Add(r)
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Next
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] TotalBack [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Decimal
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] TotalLay [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Decimal
[/COLOR][/SIZE][SIZE=2]
s("Name") = ""
[/SIZE][SIZE=2][COLOR=#0000ff]For[/COLOR][/SIZE][SIZE=2] j = 1 [/SIZE][SIZE=2][COLOR=#0000ff]To[/COLOR][/SIZE][SIZE=2] resp.marketPrices.runnerPrices.Length
[/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] (resp.marketPrices.runnerPrices(j - 1).selectionId = CurrentMarket.runners(i - 1).selectionId) [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] (resp.marketPrices.runnerPrices(j - 1).bestPricesToBack.Length = 1) [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]s("Back 3") = 0
s("Back 2") = 0
s("Back 1") = resp.marketPrices.runnerPrices(j - 1).bestPricesToBack(0).amountAvailable
TotalBack = Int(resp.marketPrices.runnerPrices(j - 1).bestPricesToBack(0).amountAvailable)
TextBox8.Text = CurrentMarket.runners(i - 1).name
TextBox9.Text = Int(TotalBack)
[/SIZE][SIZE=2][COLOR=#0000ff]ElseIf[/COLOR][/SIZE][SIZE=2] (resp.marketPrices.runnerPrices(j - 1).bestPricesToBack.Length = 2) [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]s("Back 3") = 0
s("Back 2") = resp.marketPrices.runnerPrices(j - 1).bestPricesToBack(1).amountAvailable
s("Back 1 ") = resp.marketPrices.runnerPrices(j - 1).bestPricesToBack(0).amountAvailable
TotalBack = Int(resp.marketPrices.runnerPrices(j - 1).bestPricesToBack(0).amountAvailable) + Int(resp.marketPrices.runnerPrices(j - 1).bestPricesToBack(1).amountAvailable)
TextBox8.Text = CurrentMarket.runners(i - 1).name
TextBox9.Text = Int(TotalBack)
[/SIZE][SIZE=2][COLOR=#0000ff]ElseIf[/COLOR][/SIZE][SIZE=2] (resp.marketPrices.runnerPrices(j - 1).bestPricesToBack.Length = 3) [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]s("Back 3") = resp.marketPrices.runnerPrices(j - 1).bestPricesToBack(2).amountAvailable
s("Back 2") = resp.marketPrices.runnerPrices(j - 1).bestPricesToBack(1).amountAvailable
s("Back 1") = resp.marketPrices.runnerPrices(j - 1).bestPricesToBack(0).amountAvailable
TotalBack = Int(resp.marketPrices.runnerPrices(j - 1).bestPricesToBack(0).amountAvailable) + Int(resp.marketPrices.runnerPrices(j - 1).bestPricesToBack(1).amountAvailable) + Int(resp.marketPrices.runnerPrices(j - 1).bestPricesToBack(2).amountAvailable)
TextBox8.Text = CurrentMarket.runners(i - 1).name
TextBox9.Text = Int(TotalBack)
[/SIZE][SIZE=2][COLOR=#0000ff]Else
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]' Do Nothing
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] (resp.marketPrices.runnerPrices(j - 1).bestPricesToLay.Length = 1) [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]s("Lay 3") = 0
s("Lay 2") = 0
s("Lay 1") = resp.marketPrices.runnerPrices(j - 1).bestPricesToLay(0).amountAvailable
TotalLay = Int(resp.marketPrices.runnerPrices(j - 1).bestPricesToLay(0).amountAvailable)
[/SIZE][SIZE=2][COLOR=#0000ff]ElseIf[/COLOR][/SIZE][SIZE=2] (resp.marketPrices.runnerPrices(j - 1).bestPricesToBack.Length = 2) [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]s("Lay 3") = 0
s("Lay 2") = resp.marketPrices.runnerPrices(j - 1).bestPricesToLay(1).amountAvailable
s("Lay 1") = resp.marketPrices.runnerPrices(j - 1).bestPricesToLay(0).amountAvailable
TotalLay = Int(resp.marketPrices.runnerPrices(j - 1).bestPricesToLay(0).amountAvailable) + Int(resp.marketPrices.runnerPrices(j - 1).bestPricesToLay(1).amountAvailable)
[/SIZE][SIZE=2][COLOR=#0000ff]ElseIf[/COLOR][/SIZE][SIZE=2] (resp.marketPrices.runnerPrices(j - 1).bestPricesToBack.Length = 3) [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]s("Lay 3") = resp.marketPrices.runnerPrices(j - 1).bestPricesToLay(2).amountAvailable
s("Lay 2") = resp.marketPrices.runnerPrices(j - 1).bestPricesToLay(1).amountAvailable
s("Lay 1") = resp.marketPrices.runnerPrices(j - 1).bestPricesToLay(0).amountAvailable
TotalLay = Int(resp.marketPrices.runnerPrices(j - 1).bestPricesToLay(0).amountAvailable) + Int(resp.marketPrices.runnerPrices(j - 1).bestPricesToLay(1).amountAvailable) + Int(resp.marketPrices.runnerPrices(j - 1).bestPricesToLay(2).amountAvailable)
[/SIZE][SIZE=2][COLOR=#0000ff]Else
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]' Do Nothing
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2]s("POM") = 0
tbl.Rows.Add(s)
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Next
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Next
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE]
 
Back
Top