Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2008-06-17
4
Medium Priority
?
432 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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 to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

597 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