Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

When updating list, previous list updates for some reason??

Status
Not open for further replies.

kennycad

Technical User
Jan 26, 2005
52
AU

I must have been looking at this thing too long. I am trying to populate a list with some custom classes, the issue is that when I clear the temporary list and populate with the next set of data which is then added to the master list it seems to update the previously added class.

Anyone able to shed some light? Just for the record I am only a beginner so the code/method may not be that flash.

thanks in advance
-----------------------------------


Public Class tableData

Public identifier As Integer
Public xyList As List(Of XYdata)

Public Sub New(ByVal m_identifier As Integer, ByVal m_xyList As List(Of XYdata))

identifier = m_identifier
xyList = m_xyList

End Sub

End Class

Public Class XYdata

Public xVal As Integer
Public yVal As Integer

Public Sub New(ByVal m_xVal As Integer, ByVal m_yVal As Integer)

xVal = m_xVal
yVal = m_yVal

End Sub

End Class

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim figI4 As New List(Of tableData)
Dim tmpXY As New List(Of XYdata)

tmpXY.Add(New XYdata(20, 100))
tmpXY.Add(New XYdata(30, 150))
tmpXY.Add(New XYdata(40, 200))
tmpXY.Add(New XYdata(50, 250))

'add to main list
figI4.Add(New tableData(90, tmpXY))

'tmpXY.Clear()

tmpXY.Add(New XYdata(2, 100))
tmpXY.Add(New XYdata(3, 150))
tmpXY.Add(New XYdata(4, 200))
tmpXY.Add(New XYdata(5, 250))

'add to main list
figI4.Add(New tableData(100, tmpXY))

For Each item In figI4

MsgBox("Ident: " & item.identifier)

For Each sItem In item.xyList

MsgBox(sItem.xVal)

Next

Next

End Sub

End Class
 

Instead of:

tmpXY.Clear()

use:

tmpXY = New List(Of XYdata)


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 

perfect, thankyou very much for the quick response

Cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top