VS 2008 Adding An Object To A Collection?
Apr 11, 2010
I know you are going to lough about this , but I guess I deserve it ...I am sure I am doing something wrong , but I can't find it out ...I have created a collection , lets sayMyCollectionI have also created a class , lets call itMyClass
View 2 Replies
ADVERTISEMENT
Jun 25, 2011
I am trying to add the file information of the contents of a folder to a collection. Although I am getting the collection to hold the correct number of items that the folder contains, all of the collection's items are the details of the last file in the folder.
I'm trying to use a loop to go through each item contained in the folder and then adding the item details to a collection with the following line
nCounter += 1
collFileDetails.Add(NameOfItem, nCounter)
Next NameOfItem
View 3 Replies
Apr 6, 2012
currently in my application I have a Global Collection that is a Collection of Collections.Currently I am trying to add items/ elements to one of the child collections of the Global Collection but I am unable to use the collections methods of the child.When I assign a variable to the child collection and return the collection it is just an object with the collection inside.
Ex:
Dim GlobalCollection as New Collection
Dim ChildCollection1 as New Collection
Dim tempCurrentCollection[code]......
View 3 Replies
Oct 28, 2009
I am trying to extend the functionality of the ToolStripPanel control (which is a panel hosting ToolStrips that can be moved during design-time, as I'm sure you know).One thing I wanted to add was a 'ToolStrips' property, which would be a collection of ToolStrips the user can edit via the collection editor in the designer. So instead of manually placing ToolStrips on the ToolStripPanel via the toolbox, the user can just use the property to add/remove (or even edit) them. This is of course similar to how you add/remove/edit TabPages in a TabControl.So, I came up with this code, which I have used successfully in the past for other controls:
Public Class cToolStripPanel
Inherits ToolStripPanel
Private _ToolStrips As New ToolStripCollection(Me)[CODE]....
The cToolStripPanel control inherits the ToolStripPanel control and adds the ToolStrips property, which is of type ToolStripCollection. That class, in turn, inherits the Collection(Of ToolStrip). In the InsertItem method, I add the 'item' ToolStrip to the cToolStripPanel. Of course I also need to override the RemoveItem / ClearItems methods but that's for another time.I am 100% sure that this code should works, at least for other controls. If you replace ToolStrip with Button (for example), I can add buttons via the property during design-time just fine, exactly the way I want it.But it seems that ToolStrips are special. When I try to Add a toolstrip (via the collection editor Add button), a null reference exception occurs. I've been trying to debug this all day and I've finally come up with a possible candidate for the problem... (I've actually used design-time debugging for the first time ever, which was pretty cool, and which showed me that the InsertItem method is not run!)
I think the problem is that the collection editor cannot create a new instance of the ToolStrip class. I can remember when trying to inherit from the ToolStrip, I was forced to add a constructor, because the ToolStrip "has more than one constructor that can be called with no arguments".Perhaps this is causing my problem? Do I (and if yes, how?) have to somehow control the creation of a new instance of the ToolStrip? Or am I completely off track and that is not what is causing the problem? I'm sure that it's a problem with the ToolStrip class, since I can use the exact same method with other controls just fine. It's only when I change the type to ToolStrip that it starts getting angry at me....
View 1 Replies
Nov 16, 2009
Dim wBrowser As New WebBrowserTabControl1.SelectedTab.Controls.Add(wBrowser)I used the above code to add a WebBrowser to a tab, but I have no idea how to use declarations for it after adding it in code. I'm mainly after the
View 4 Replies
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
Mar 12, 2010
I am creating an instance of a Generic List collection and I am surprised to find that I can't add more than one value to it at a time. I was thinking there was going to be something like what you can do with arrays, where you can add a group of values to it at creation. I saw the AddRange method, but that seems to add another collection to the end of this collection, which is not what I want. So my code is:
vb
Dim MyList as New List(Of String)
MyList.Add("John")
MyList.Add("Bob")
[Code].....
View 18 Replies
Sep 27, 2011
I'm trying to populate class properties where one property is a list collection. I get a NullReferenceException when trying to add to the list collection. The code (litlle bit simplified) is here:
Public Class Portfolio
Property Name As String
Property Assets As List(Of Asset)
Public Sub Populate(ByVal data As DataTable)
For Each row As DataRow In data.Rows
[Code] .....
I have a nested class "Asset" inside the class "Portfolio". Everything goes ok until the line
Me.Assets.Add(asset)
Which gives me the NullReferenceException error.
View 4 Replies
Jun 2, 2011
I'm trying to make a collection class for buttons to address them as a whole, only I want to design the buttons at design time, and not add/set their properties programatically at runtime. Each button has its own image, so it doesn't seem right to add a bunch of lines of code which assign the properties when they're always going to be the same thing.Is it possible to create the controls at design time and then add them to an array at runtime? I did this, iterating through the buttons on the form and adding each of them to the class below.The problem is that once they're added they seem to be a different instance because changing their positions has no effect on the design-buttons on the form. Essentially i wanted the collection to be a reference to the items belonging to the form.Is that possible or should I be doing this a different way?[code]
View 2 Replies
May 7, 2010
I have run into this problem a number of times, and I am not sure what I might be doing wrong - or if this is just a bug, or not going to work.I have a collection that I setup on my own (eg, collection class). I then cycle a Log file that has text entires and I read those, and then parse the entry and attempt to add it to my collection.
But as each entry is added, ALL records just get duplicated - in other words, as I add entry 2, both entrys 1 AND 2 wind up with the same values - as I add 3, all 3 entries get the same value - and this continues no matter how many entries. For example,
if I added 100 entries, I would have 100 duplicates of the last record added.I have stepped through the debugger and watched this occur and just cannot figure out why this is not working as it should. Here is the code...
While
Not objReader.EndOfStream
' Read one full line
[code]....
No matter what I do, my lstSent collection just winds up with EVERY entry being the same as the last entry added.
End
IfFalse'
Add the elements into the collection if its a "Sent" itemElem = objReader.ReadLine
View 7 Replies
Sep 27, 2011
In VB.Net is every ObjectCollection Zero based except 'Collection' object itself ???
Like if you have an ObjectCollection like attachments for a mail for example, which has .Count in it, then i have seen it is Zero based
But in case of the 'Collection' object it is 1 based. 'ie dim cc as new Collection.
I am just confirming this because you can't keep checking for each collection of objects if it is zero based or 1 based, because if you use the For...Next loop, then do we have to think always if it is
For iItem=0 to ObjectCollection.Count-1
-OR-
For iItem=1 to ObjectCollection.Count
View 2 Replies
Jan 5, 2011
In an application I am working on I have created a product class which represents an inventory item. I have also created an inventory class which represents a collection of product objects. In the constructor of the Inventory class I load 4 products into a product collection. Each product consists of a code, description price and quantity.
[Code]...
View 3 Replies
Mar 27, 2009
i have a user define object which i'm initializing with data from external datafiles.... the purpose of this object is to reduce the amount of disk/data access and processing required every time i need to add an instance of this object to a collection.so, whenever i add a copy of this object to a collection, i would simply reference the "base" object, and avoid having to process all the data and perform the conversion and so on...the issue is when i add the object
Collection.add(Base_Object, Key)
the collection ITEM is a Reference to the base object and not a copy.
View 6 Replies
Oct 28, 2009
I can't figure out how to determine the type of an object in a collection. I want to do a For Each ... Next loop over the items in the DropDownItems collection of a ToolStripMenuItem. For those items that are ToolStripMenuItems themselves I want to take some kind of action. (The collection can contain other types of items, such as ToolStripSeparators). So I need to say something like: If Typeof(item) = ToolStripMenuItem Then .
View 1 Replies
Aug 30, 2010
I'm trying to loop through a collection object in vb2010.The code was originally used in Vb6 The book said that I needed to code a NewEnumerator method first in order to be able to loop through my collection. I coded the following:
[code]...
It gives an error for IUnknown, staging that IUnknown is not accessible in this context because it is a 'Friend'.In the line in the function I removed the Set since it's no longer needed.The error message for this line is '_NewEnum' is not a member of 'Microsoft.VisualBasic.Collection'What are these messages and how do I fix this in VB 2010?m_colCourse is not a system collection.
View 1 Replies
May 17, 2012
Currently, I have a listbox lstInventory where I have loaded some database information from a .mdb file. I am able to add new records, and they all display correctly.
Yet, I can't seem to retrieve or access any of the listbox items. (Not trying to reaccess database in here, yet). I am hoping to "Edit" an existing database record by matching it to the lstInventory's selecteditem property. Unfortunately, I am not able to retrieve anything (tried traditional CType(lstInventory.selecteditem.ToString, String) approach, as well as a debug.write approach (which I can't seem to display, even with a Listener-which is another issue in itself).
Furthermore, when I check the listbox.items.count property, it prints out as a "0" [using a messagebox.show()]
I have tried searching multiple forums, but found lots of "database into listbox" threads, and the MSDN website hasn't helped me yet. Do I need to know the collection's name (what would it's name be based on ?)? Or am I not converting the object into a printable/countable quantity?
View 5 Replies
Apr 8, 2009
I have a class which extends HashSet(Of T).I am trying to evaluate some custom properties of this HashSet during execution and make decisions based on those values.
During debugging, I am pausing execution and adding a Watch on my instance of this HashSet.
The Watch only provides me with a view of the Count of the HashSet and the objects contained by the HashSet.How can I get the Watch to show me the other properties of the HashSet?
View 1 Replies
Feb 19, 2008
i have a collection wherein i store an object for example i have a textbox Object which have a text value = "TEST" then i store this on the collection then i change the text Value to = "SAMPLE" then i notice that the value of the first Text Object the is also change to SAMPLE...
What am doing is an UNDO function wherein i store the object state in a collection..why does the value of the textbox object changes in a collection
View 13 Replies
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
Jun 8, 2009
I'd like to store a set of key/value pairs in the application settings of my ASP.NET web app, but I'm not finding a straightforward way to do that. For example, these two questions tell me that StringDictionary etc. won't serialize to XML and suggest that I'll have to roll my own implementation. But it seems like this should be easier to do; after all, web.config is XML and < applicationSettings> is essentially a collection of key/value pairs, so it feels like I'm missing something obvious. Given my specific case below, do I really have to roll my own serialization, or is there an easier workaround?
The web app in question is a basic contact form that sends email to different recipients based on the value of a parameter; e.g. [URL]...The goal is to be able add or remove recipients (or change their addresses) by editing the web.config file so that I don't have to recompile and can easily maintain different configurations in test and production environments. For example:
// I can use something like this for the sender address SmtpMsg.From = New MailAddress(My.Settings.EmailSender)
// And then just edit this part of web.config to use different addresses in different environments.
<setting name="EmailSender" serializeAs="String"> <value>webcontact@exampledomain.com</value>
[Code]...
View 2 Replies
Jun 10, 2009
I am moving from VB to C#. I am trying to loop through a collection class which is a collection of data classes but I can't seem to get the actual values out of the data class properties(find the correct code to do so). I have a method that loops through the collection class(Contacts) and saves each record(Contact). I am using reflection because my method will not know if it is Contacts class or a Customer class and so forth. Here is my code in VB(watered down)
Public Function SaveCollection(ByVal objCollection as Object, ByVal TableName as string, ByVal spSave as string)
Dim objClass as Object
[Code]....
The C# code keeps returning null. In my locals window I can see the proprties on the class on objClass and the value of the propery but I can seem to figure out how to access it through code. I used the DictionaryBase because that seems to closely match would I need to do. My data class(Contact) has a bunch or properties that match the field names in the database of the Contact Table. After I get the propInfo variable set I then set up my SQLParameter with the fieldname, datatype etc and then set the value to the propInfo.value.
View 5 Replies
Feb 8, 2012
I like the PHP way of doing things but, it seems I am stuck with using a Collection of Object's to store/retrieve the data I need. I have my Collection loaded with my Objects's and the code to iterate through the collection, my problem is I am unable to retrieve the "key" as it would be called in PHP (I believe in this case it is actually the name of the object).
Consider the following example:
Dim xDoc As XPathDocument = New XPathDocument(fName)
Dim xNav As XPathNavigator = xDoc.CreateNavigator()
Dim sender As XPathNodeIterator
[CODE]...
As you can see, I am navigating an XML document, and creating an Object with some Key/Value pairs. The Object would look something like this if it were in JSON:
{"name":"John Smith","address1":"123 Anywhere St.","city":"This City","state":"FL"}
When I iterate though the Collection I can only get the value of the object, but I need the Key, in this instance I want "name","address1","city","state" to be stored in a variable for each iteration.
View 2 Replies
Aug 12, 2011
I have an object with a property that is a collection. When I point the PropertyGrid to the object it displays the ellipses for the collection. When I click it I get the generic collectioneditor. Of course the Add put fails because my collection is strongly typed. I need an example of how to create a collectioneditor that will create my collection's objects.
View 4 Replies
Mar 17, 2009
i have created my own custom propertythe property is of type collection ,it displays a form which allow the user to add a list of images and strings,it stores the data in a collection ,my problem is , i have noticed that after adding items to the collection at design time , there is no code generated in the .Designer file of the form and there for when i close the for / save it and reload it , all the items that i added to my custom property are gone.my question , what did i miss here ? how do i make my custom property generate code at the .designer file for the items i have added to my property?
View 1 Replies
Sep 18, 2010
I am using LinqPad to learn Linq by querying the NetFlix OData source.Here is the query I got working which is awesome.[code].....
(Pardon all the comments...it is a testament to the fact I am experimenting and that I will change the query for various needs).There are two thing I cannot figure out.First.Let's say I only want to return the first 10 results.Second (and most importantly). I want to filter by a partial string of the genre.Each title contains a Genres collection. I want to show only Genres where the Name contains a certain string (like "Family").Even better filter using Titles where genre.name.contains "firstFilter" AND "secondFilter".Basically, I want to filter by genre(s) and I cannot figure out how to do it since Title contains its own Genres collection and I cannot figure out how to return only title that are in one or more genres of the collection.
View 3 Replies
Oct 6, 2009
Datatable object within class function + garbage collection?
View 3 Replies
Nov 5, 2010
Basically I have a simple while loop that loops through a datareader and saves the information into a object collection. Later on in the code I have a simple function that loops through the collection and exports the data to excel. The later part works flawlessly.OK the issue is that for some strange issue If I just let the while loop work as it should it misses records in the datareader stream. Now it sounds crazy but if i add a counter (x=x+1) along with a message box at the end of the loop to tell me the value of the counter (msgbox(x)) it ALWAYS saves the correct amount of records. If I take the msgbox line out it ALWAYS misses records. I am so boggled right now.[code].....
View 18 Replies
May 4, 2012
I am attempting to write a Dictionary Collection to a file.The Collection is structured like so:
GlobalCollection (Collection of TestCollection)
(0)
[KEY]
[code].....
View 2 Replies
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
Jan 23, 2009
If I use a single variable of type Excel.Worksheet to reference Worksheet1, and then change it to Worksheet2, Worksheet3 and so on, is it adequate to simply do "Marshal.FinalReleaseComObject(worksheetVariable)" once at the end? Or would I be left with some references still in memory? In other words, do I need to do a "Marshal.FinalReleaseComObject" before each re-assignment?
View 3 Replies