liversen
asked on
How to edit structure items on a system.collections.generic list (of )
Hi
I have a quite complex problem where I have an already populated list of a structure and I need to edit the individual items.
Here's an example of code that does not work for me:
Imports System.Collections.Generic
Public Class Form1
Private Structure myStringStructure
Dim mystr As String
End Structure
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim hj As New List(Of myStringStructure)
hj.Add(New myStringStructure)
hj(0).mystr = "hmm"
End Sub
End Class
It tells me that: "Expression is a value and therefore cannot be target of an assignment."
So how do I edit the mystr of the lists entry 0. ?
Thanks in advance
I have a quite complex problem where I have an already populated list of a structure and I need to edit the individual items.
Here's an example of code that does not work for me:
Imports System.Collections.Generic
Public Class Form1
Private Structure myStringStructure
Dim mystr As String
End Structure
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim hj As New List(Of myStringStructure)
hj.Add(New myStringStructure)
hj(0).mystr = "hmm"
End Sub
End Class
It tells me that: "Expression is a value and therefore cannot be target of an assignment."
So how do I edit the mystr of the lists entry 0. ?
Thanks in advance
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That was exactly what I was looking for. I could have spent a lot of time trying to solve it and then it appears that the solution is so simple. I guess I just got on to structure instead of class because I'm used to VB 6.
Thanks for the solution
Thanks for the solution
Glad to help!
Public Class Form1
Private Structure myStringStructure
Dim mystr As String
End Structure
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim hj As New List(Of myStringStructure)
Dim oNewOne As myStringStructure = new myStringStructure
oNewOne.myst = "hmmm"
hj.Add(oNewOne)
End Sub
End Class