Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / March 2006

Tip: Looking for answers? Try searching our database.

Problem with - Edit Item of Collections.Generic.List(Of SearchAreaListItem)  

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
snesbit - 27 Mar 2006 19:28 GMT
I have a structure called SearchAreaListItem.

The structure has some properties.

The application implements this as a collection.generic.list(of SearchAreaListItem)

I load the collection up  item at a time stuffing values into the item then adding the item to the
collection.

Now here come the rub.

There is one property attached to SearchAreaListItem, that I need to CHANGE so we can track whether the item has been accessed.

However when I try the following;

   STEP 1:    Dim SearchAreaList as new collection.generic.list(of SearchAreaListItem)

   STEP 2:    Call function to load each item and add to collection

   STEP 3:    Try to set the Accessed property on Item X

                            SearchAreaList.Item(x).Accessed = True

   STEP 3   is not acceptable to Visual Studio and I get the design time error

                       Error 1 Expression is a value and therefore cannot be the target of an assignment.

Why can't I set a property of a structure through an index of  a collection.generic.list(of SearchAreaListItem)??
Mattias Sjögren - 27 Mar 2006 19:51 GMT
>Why can't I set a property of a structure through an index of  a collection.generic.list(of SearchAreaListItem)??

Becuase a structure givs you a value type, and therefore the List
indexer returns a copy of the instance. Even if the compiler let you
do what you want, you would modify the temporary copy, not the one in
the list. The solution is to use a class (a reference type) instead.

Mattias

Signature

Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Kerry Moorman - 27 Mar 2006 19:52 GMT
snesbit,

In order to do what you want, SearchAreaListItem needs to be a class, not a
structure.

Kerry Moorman

> I have a structure called SearchAreaListItem.
>
[quoted text clipped - 24 lines]
>
> Why can't I set a property of a structure through an index of  a collection.generic.list(of SearchAreaListItem)??
Cor Ligthert [MVP] - 28 Mar 2006 06:41 GMT
Snesbit,

It sounds for me so crazy

A generic list of a value that is placed on the stack

Cor
 I have a structure called SearchAreaListItem.

 The structure has some properties.

 The application implements this as a collection.generic.list(of SearchAreaListItem)

 I load the collection up  item at a time stuffing values into the item then adding the item to the
 collection.

 Now here come the rub.

 There is one property attached to SearchAreaListItem, that I need to CHANGE so we can track whether the item has been accessed.

 However when I try the following;

     STEP 1:    Dim SearchAreaList as new collection.generic.list(of SearchAreaListItem)

     STEP 2:    Call function to load each item and add to collection

     STEP 3:    Try to set the Accessed property on Item X

                              SearchAreaList.Item(x).Accessed = True

     STEP 3   is not acceptable to Visual Studio and I get the design time error

                         Error 1 Expression is a value and therefore cannot be the target of an assignment.

 Why can't I set a property of a structure through an index of  a collection.generic.list(of SearchAreaListItem)??

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.