Solved

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

Posted on 2008-06-17
4
408 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

815 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