Adding Items To A List (of Object)?

Mar 28, 2010

I have some code that adds items to a List(of Object).

Here's my original code

Dim BeaconStoryList as New List(Of My.StoryType)
Dim BeaconStory as New My.StoryType
Dim NewStories() as New Foriegn.StoryType = GetStories

[Code]....

But as soon as the code assigned "Chicken" to BeaconStory.Title, then BeaconStoryList(0).Title would also change to "Chicken".

With my second version of the code this did not happen.

It's as though it was placing pointers into the elements of the array rather than values. If that is the case, however, then why does my second version of the code work - I'm still passing in the same thing - aren't I?

View 3 Replies


ADVERTISEMENT

Why Is List.add() Adding Items To Object AND Source Object As Well

Jun 15, 2011

I need to be able to add elements to a copy of mylist.testlist without modifying the global mylist object. (Which seems to be happening via the below code.)When I am working on x, which should be a totally separate object, mylist is getting modified as well. How can I fix this? I have worked with lists extensively and never seen this behavior before. I have tested and reproduced the problem in .NET 3.5 and .NET 4.0 on Win 7 Pro 32bit.

Source Code:

Public Class Form1
Public mylist As New test
Sub Main()

[code]....

View 1 Replies

List.count While Adding Items To The List Increments Returns 0

Jul 20, 2011

I am attempting to read the results from a SQL query into a List(Of) and I can see the List.count while adding items to the List increments, however in another part of my code when I am attempting to read the List the List.Count returns 0. My List is as follows:

[Code]...

View 4 Replies

Adding Items From List Box

Jan 28, 2010

I'm learning how to add items from a list box to a combo box. I'm trying to follow what's going on in the function loop and comparing a boolean and selected index. I can see that it's comparing the item chosen to each item already in the combo box to make sure that it's not already there. If function finds that it's not in the list it sends back that it is true that the item is not in the list.

It then continues to the statement that adds item to the list. The code for the double click event is working fine and items are getting added to combo box. However, the code for the add button isn't functional. I'm not seeing why it doesn't work? I coded out the original code, and replaced with something I thought might work but it still isn't functional. [Code]

View 1 Replies

Adding Items To A List Box

Mar 9, 2009

[Code]...

Mod Edit: Please use code tags when posting your code. Code tags are used like so =>

View 1 Replies

Adding Items To List Boxes?

Oct 19, 2010

I'm using the free version on Visual Basic 2008 (through school).The assignment is to populate a list box from user input text. The textbook only talks about populating a list of known items.ex animalListBox.Items.Add("dog") Which works just fine, however, we don't know what the user will input.

So, how should I be thinking about this?

View 2 Replies

Adding List Of Items To Array?

Apr 14, 2010

I'm still learning VB.net and there is a bit of code I have added which is an array and I want to add a list of items to the array. If that makes sense. I have 6 classes two have arrays.

Here is the code from one of the classes
Public Function getItems() As Array
Return _LevelItems
End Function

How would I add the item list to this? Where do I put it? Like underneath it or in the items class? That code is in the Level class.

View 5 Replies

.net - Dynamically Adding Items To An Un-order List In Asp.net

Feb 22, 2010

if i create a html ul. and wanted to dynamically add list items to this list. so i have :

[Code]....

is there a way i can add list item to this list dynamically in asp.net i am using vb

View 1 Replies

Adding A List Of Items To A Listbox From A String?

Aug 18, 2011

I have a small program that talks to a server, grabs the content from a website using a php webscraping program and then places the results in a listbox as a string. My problem is taking this string and creating a list from it. Each item in the string is followed by a | (pipe). I have included the code that I've tried below:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim str As String
Dim start As Integer = 1

[code]....

View 5 Replies

Adding Items To List Results In Duplicates?

Jul 29, 2009

I have this code to return a list of fund sources for our organization.

Dim FundSourceList As New List(Of FundSource)
Dim fs As New FundSource
If results.Count > 0 Then[code].....

The problem is that when I loop through the resulting FundSourceList all it shows is the last value. For example, if I have three fund sources (state, federal, athletic), then when I use this code to loop through all I get listed is athletic, athletic, athletic.

For Each FundSource In FundSources
Debug.Print(FundSource.FundDescription)
Next

So I change the code to this. I moved the creation of the fs variable inside the loop.

Dim results = From result In dsResult.Tables(0) Select result
Dim FundSourceList As New List(Of FundSource)
If results.Count > 0 Then[code]....

This works fine but now I'm creating a new class over and over again. It seems a little inefficient to me. Can I not create the class outside the loop and use it over and over again?

View 3 Replies

Adding Items To The List At Creation Time

Apr 13, 2010

In c# I can initialize a List at creation time like var list = new List<String>() {"string1", "string2"};

[Code]...

View 2 Replies

Adding And Removing Items From The List And Tree Views

Mar 10, 2009

I am trying to learn how to work with the different controls in Visual Studio for VB.Net in particular the List View and Tree Views. I don't have any code to show as I am not working on anything in particular just messing around with it to learn what the different controls do that weren't covered in my Intro to VB.Net class last semester.I would like a clearer explanation on how to actually use code for these controls. In particular adding and removing items from the List and Tree Views using code.

View 1 Replies

Adding Value To Items In Text Box From List Box In Order To Calc?

Jul 16, 2011

adding value to items in text box from list box in order to calc

View 3 Replies

VS 2010 "Object Reference" Error When Adding Object To List (Of T) Property

Apr 25, 2011

I have a class that has a property that I declare like this:

VB.NET
Private _DirectoryList As List(Of FileDirectoryInfo) ''' <summary> ''' Array of directories. ''' </summary> ''' <value>Object</value> ''' <returns>Directory array list</returns> ''' <remarks>N/A</remarks> Public Property Directory As List(Of FileDirectoryInfo) Get Return _DirectoryList End Get Set(ByVal value As List(Of FileDirectoryInfo)) _DirectoryList = value End Set End Property

[Code]...

View 2 Replies

Adding To A Currently-null List (Of Object)

Aug 5, 2011

I am not sure what I'm doing wrong, but I need some guidance from people smarter than me...

View 1 Replies

VS 2010 : Adding Selected Items In List Box To Multi Picturebox?

Aug 9, 2011

building simple program that i could print index pictures to 11x17 size paper. and came across with listbox multi items selected and wanted to add them to different picture boxes?

View 1 Replies

Accessing Items In List Of Object?

Nov 6, 2011

I have created a list of another class and loaded the list with data. using breakpoints I can see that the data is loading and visible in my form page. However, when I attempt to access the list using a For Each loop, I get an error saying that "Value of type Customer can not be converted to Integer"I am trying to follow examples from tutorials on accessing list elements, but they are never lists of objects, so I am not sure what I am doing wrong.

My class that I have made a list of:
Public Class Customer
Private m_firstName As String

[code]......

View 2 Replies

List(T) Object - Add And Remove Items

Aug 12, 2010

Good example using the List(T) object. I need to be able to add and remove items from it.

View 7 Replies

NullReferenceException Error Adding Object To A List

Jun 20, 2012

I'm trying to add objects from a class I created using data from an excel worksheet to a list using a for loop [code]When I run it I receive "System.NullReferenceException was unhandled by user code Message=Object reference not set to an instance of an object."

View 4 Replies

Populate Listbox From Items In List Object?

Jan 4, 2012

trying to write an updateview method to basically clear the contents of the current listbox and then loop through a list of objects and pass 2 items from each of the objects in the list into the listbox.This is what I have so far

vb.net
Public Sub updateview()
holidaylistbox.items.clear()

[code].....

View 4 Replies

.net - Adding New Object To Generit List Overwrites Previous Values?

Jul 15, 2010

I have a problem with a generic list, which consists of intances of a class i created. I am just amazed, each time I add a new object to the list, it overwrites the previous entries. Here is a code sample, i just can't beleive it. I am using visual studio 2010:

Dim translations As List(Of TranslatedValue) = New List(Of TranslatedValue)
If Session("ctlTexts") Is Nothing Then
Dim reader As IDataReader = DataAccessFunctions.db.GetDataReader("SELECT [ControlID], [ControlTextEN], [ControlTextDE], [ControlTextBG] FROM [dbo].[tbLanguage]", GetConnectionString)

[code]....

View 2 Replies

VS 2008 Adding Class Object To List Or Array In A Different Class

Jun 21, 2010

I am trying to create an list or an array of a class.Here is my "Ingredient" class that I am trying to create a list of:[code]In my "recipe" class, I am want to create a list (or array) and I am drawing a big blank on how to do it. Can anyone point me in the right direction?

View 2 Replies

List Of T Find Date Or Other Property In A Object In The List - Then Return Found Object?

Sep 3, 2009

After reading all the examples for list of T exists and Find and find first, none show how to handle multi-property objects. Below is bare bones example maybe someone could flesh out to show how this should be done.

Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim DatePriceList As New List(Of DateAndPrice)
DatePriceList.Add(New DateAndPrice(Date.Parse("1/1/2000"), 10.12))
DatePriceList.Add(New DateAndPrice(Date.Parse("1/2/2000"), 11.12))

[Code]...

View 3 Replies

Display A List (Of Object) Which Has Single Objects And Child List (Of Object)?

Sep 6, 2011

Limited to using v2.0 of .Net framework (we use VB.net) due to environmental constraints on our servers.I've got an ASP.net webpage which pulls data from a webservice that performs checks on user accounts in active directory. Operators can check multiple accounts at one time using the web interface. The webservice returns a list(of AccountCheck) objects which themselves contain single properties like username, email address, and List(of AccountError) objects which contain multiple properties.[code]What I want to do is using some kind of repeater, create multiple panels or divs which contain labels showing the username, email etc, and a gridview which has the accounterror list bound to it to show all the errors. The users could be checking 2, 5, 7 accounts at once, and is dynamic.

View 2 Replies

VS 2010 Custom Type Array / List With Adding Items And Specifying Custom Type Variable

Jun 21, 2011

I recently downloaded VB 2010 Express so i am quite new to the language, but i have worked with dark basic, which seems to b very similar.Anyway, my problem is that i cannot seem to correctly set out my array of a custom type/class. i am trying to create two arrays, one of available entities and another of selected entities of which the user selects the entities to be dealt with in irrelevant ways. i have creates a button (called test) which adds some entities to the available list and all the entities come back the same value but they shouldnt be as you'll c in the code. i have run the step into command a found that "available.item(#).Name = " will change all of the entity's names.As of current i am working with lists as the array kept asking for a 'new' statement but i couldnt figure out where to put it.[code]

View 7 Replies

Cast A List Of Object To List Of Interface That Object Implements?

May 19, 2009

I am working in VB.net and have a Class, Foo, that implements an interface, IBar.I have a List of Foo's, but I need to pass a list of IBar's into a function, but I keep getting casting errors, even when I use DirectCast.My code is [code]MainWorks works, but it would be really annoying and inefficient to have to do that everywhere I want to call this function.

View 4 Replies

Word 2007 Adding Adding Values To Combo List Box

Jun 7, 2011

I am trying to create a simple Word doc that when the user presses the button it takes the information in the boxes and tosses it into a template style paragraph. But my issue is that I have two combo list boxes as seen in the picture. I want to have two values in the drop down list as seen in the labels next to them but for the life of me I can't figure out how to do this in Word 2007. In Visual Studio this is much easier but I am work and need to snap this out for the folks at work. Is there an option that I can choose in the properties where I type in the values for each drop down or do I have to add them in at run time?

View 1 Replies

How To Quickly Transform A List(Of Object) Into A List(Of "Object.field")

May 29, 2012

Suppose I have a list of Cat.

Public Class Cat
Public Property id As Guid
Public Property name As String
Public Property race As catRace
End Class

How can I quickly transform this List(Of Cat) into a List(Of Guid) using the id property?

I could do :

Dim newList As List(Of Guid)
For each item in catList
newList.Add(item.id)
Next

But I think there must be a way to do this faster (1 LOC). I just can't find how.

View 3 Replies

Determine If Property Is Generic List<of T> Via Reflection And Loop List Items

Oct 1, 2009

I'm looping all the properties in an object via reflection:

For Each p As PropertyInfo In values.[GetType]().GetProperties()
If p.CanRead Then
'Do stuff
End If
Next

how to determine whether the property in question is a generic List(Of T)? If it is I need to loop the list itself.

I've experimented with GetType and TypeOf but have not managed to get anything working.

To clarify, I want to keep this generic. I do not want to specify the type of T, I need to loop the list items and call the ToString method on each item. T could be one of a number of different types (application specific reference types). Is it possible to do this without specifying types?

(VB.NET 2005 with .Net 2.0)

View 3 Replies

Placing Selected/unselected Items In Checked List Box Into List Boxes?

Mar 16, 2011

This program is supposed to allow the user to check items in a checked list box. If the item is checked, it goes into the Completed List Box on the right. The program then adds the unchecked items to the Pending list box on the left. I keep getting placement values (e.g. O,1,2) instead of the strings (e.g. "Key Returned") in the list box results (see photo attached)

Public Class frmCheckOut
Dim i As Integer
Dim cleaning As String = "Cleaning Inspection"
Dim damage As String = "Damage Repaired"

[code].....

View 3 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved