Solved

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

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.NET 2008 Winforms Signing 13 41
Help with error in Query 2 37
Name Space error VS2015 1 35
vb.net datagrid point 4 16
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

685 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