Solved

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

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
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 …

792 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