Solved

How to edit structure items on a system.collections.generic list (of )

Posted on 2008-06-17
4
405 Views
Last Modified: 2012-06-27
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
0
Comment
Question by:liversen
  • 2
4 Comments
 
LVL 21

Expert Comment

by:mastoo
ID: 21803240
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)
       Dim oNewOne As myStringStructure = new myStringStructure
       oNewOne.myst = "hmmm"
        hj.Add(oNewOne)
    End Sub
End Class
0
 
LVL 24

Accepted Solution

by:
Jeff Certain earned 500 total points
ID: 21806083
Alternately, use a class instead of a structure:

Public Class myStringStructure
      Public mystr As String
End Class

This was you can edit it after you add it.
0
 
LVL 1

Author Closing Comment

by:liversen
ID: 31467963
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
0
 
LVL 24

Expert Comment

by:Jeff Certain
ID: 21806989
Glad to help!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now