W
wooz
I've got ArrayList filled by some objects. I bind it to listbox.
Public class clsX
Private pUserName as string
Public Property UserName() As String
Get
Return pUserName
End Get
Set(ByVal Value As String)
pUserName = Value
End Set
End Property
End Class
-----
Dim Ar as new ArrayList
Dim x1 as new clsX
Dim x2 as new clsX
x1.UserName="aaa"
x2.UserNAme="bbb"
Ar.add(x1)
Ar.add(x2)
mylistbox.DataSource = Ar
mylistbox.DisplayMember = "UserName"
mylistbox.ValueMember = 'is assigned to other propoerty class X (not shown
above)
Now I get selected object in listbox:
dim tmpX as clsX
tmpX=mylistbox.SelectedItem()
Then i edit property "UserName"
tmpX.UserName="John"
Everything is fine but why this change is not seen in ArrayList Ar. Does
method "SelectedItem" of listbox returns a copy of object from ArrayList Ar,
or maybe listbox has copy of whole ArrayList Ar ?
Public class clsX
Private pUserName as string
Public Property UserName() As String
Get
Return pUserName
End Get
Set(ByVal Value As String)
pUserName = Value
End Set
End Property
End Class
-----
Dim Ar as new ArrayList
Dim x1 as new clsX
Dim x2 as new clsX
x1.UserName="aaa"
x2.UserNAme="bbb"
Ar.add(x1)
Ar.add(x2)
mylistbox.DataSource = Ar
mylistbox.DisplayMember = "UserName"
mylistbox.ValueMember = 'is assigned to other propoerty class X (not shown
above)
Now I get selected object in listbox:
dim tmpX as clsX
tmpX=mylistbox.SelectedItem()
Then i edit property "UserName"
tmpX.UserName="John"
Everything is fine but why this change is not seen in ArrayList Ar. Does
method "SelectedItem" of listbox returns a copy of object from ArrayList Ar,
or maybe listbox has copy of whole ArrayList Ar ?