Accessing And Adding Items To A Collection That Is In A Collection?
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]......
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
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?
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.
Is it good practice to store sub-collections of item X inside a parent collection of item X for caching 'filter-queries' which are performed on the parent collection? (They won't be used together (as in color AND type).) Or is it also ok to just Loop over the collection and return the correct entities in a temporary collection?
I have been researching for a couple of days now and to no avail. Does Anyone know how to make a custom collection that take advantage of the collection editor? I would like to be able to have 3 Color Values, 1 Boolean and 1 String.
I'm trying to support Basic.NET on my framework so I'm trying to convert C# 4 code to Basic.NET 10. Microsoft is committed to "co-evolve" these two but I'm having a problem with collection initialization... I found that I can initialize a collection much like in C#:
I've got the following ADO.NET Entity Framework Entity Data Model:I want to find all the Policyholders with both a Service of a given Id and also a Keyword of a given Status.
This LINQ Does Not Work:
Dim ServicesId As Integer = ... Dim KeywordStatus As Integer = ... Dim FoundPolicyholders = From p As Policyholder In db.PolicyholderSet.Include("Keywords").Include("Services") _ Where p.Services.Id = ServicesId _ And p.Keywords.Status = KeywordStatus _ Select p
The Where clause cannot search the p.Services and p.Keywords EntityCollections in that way.
I've been working with a CMS called InsiteCreations 2008. I'm running into an error I just can't wrap my head around. I would even be willing to compensate anyone a small amount over paypal, for a solution. The error is rare in occurance, and appears when clicking about 3-4% of links to other pages within our CMS.The full code page is quite large, but there seems to be only one function associated with the error. The error also only appears when not logged into the CMS. If logged into the CMS, clicking the link simply displays the page as normal. I have already checked permissions on the page from the CMS admin console, and it is public.
The error message is as follows:
Server Error in '/' Application.Collection index must be in the range 1 to the size of the collection. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
I have a simple subroutine that loads a list from a database. I would like to be able to use the same code to load a ListBox and a ComboBox by defining the list type as the common abstract base class ListControl, and see no reason why I can't - except that VB.NET doesn't expose/implement/whatever the Items collection in ListControl. I note with frustration that this is not the case in ASP.NET. At moment my code is ugly because I have to check what type of list control I have passed in, in order to cast it to a type that has an Items collection. (My code may be ugly for numerous other reasons too, but it is beautiful to me). Is there a way to rewrite the code to avoid having to go through the testing and casting nonsense? (I've stripped it down somewhat so that all that remains is where the problem lies).
Sub loadList(ByVal db As SqlDatabase, ByVal strCommandText As String, lstHost As ListControl, Optional bClearList As Boolean = True, Optional bIsListBox As Boolean = True) If bClearList Then
i am trying to sort the items in a collection(of T), by the start date. but i do not know how to do it. i do know that we have to implement list properties.
I have a class that represents some business object, such as this:
Public Class MyObject Inherits SomeBaseObject ' Implements INotifyPropertyChanged and IDataErrorInfo Private mMyVariable as Integer Public Property MyVariable as Integer
[code]....
SomeBaseObject implements both INotifyPropertyChanged and IDataErrorInfo, such that a Validate method will populate the appropriate IDataErrorInfo fields when setting the property values.I also have a collection that supports change events, which I eventually bind to a WPF DataGrid.
Public Class MyCollection Inherits ObservableCollection(Of MyObject) End Class
Part 1: Let's say that I have a business rule which says that no two items in my collection may have the same value for MyVariable. How do I set up my events (or implement additional interfaces somewhere) to perform this cross-item validation whenever the property value changes on any item in the collection?
Part 2: Suppose I have a list of integers such that whenever I add a new MyObject item to an instance of MyCollection or change the MyVariable property on any item already in the collection, the value of the MyVariable property must exist in this list of integers?
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
I often have a class defined and I also define another class that is simply a collection of the other class. To do this I found it easiest just to define the other class as Inherits List(Of Type). The reason I define a collection class is to add extra functionality to the collection. Take the following code for example.
Class Car Property Name As String Property Year As Short
[Code]....
how can I define my own collection so that I can reference it by index or name like that. Right now I can only reference it by index.
removal of items in a collection or list using the " For Each " statement to iterate through.This code works:
For Each item As ListViewItem In ListView1.SelectedItems ListView1.Items.Remove(item) Next
This code does not:
For Each itemChecked As Object In CheckedListBox1.CheckedItems CheckedListBox1.Items.Remove(itemChecked) Next
I have been reading on this for hours today to find out why the first code block works, but the second does not.What I've learned is the "For Each" statement implements the IEnumerable interface. I have seen these terms used many times and scratched my head when it didn't make scense, then just moved along, something to strain my brain about later.Today was later...So since the IEnumerable interface is used, the .GetEnumerator method of the IEnumerable interface is called upon at the beginning of the "For Each" block, this evaluates the collection or list as in: For Each item As ListViewItem In myCollection This is done at the beginning of the iteration through the myCollection, so if the myCollection is altered as in:
For Each itemChecked As Object In myCollection CheckedListBox1.Items.Remove(itemChecked) Next
The altering of the list returns the error:List that this enumerator is bound to has been modified. An enumerator can only be used if the list does not change.
I want to display a list of open windows on my computer in a rich text box. So, I'm trying to store the names of all windows in myString, and then set RichTextBox1.Text = myString.
Here's the code
Imports System Imports System.Collections.Generic Imports System.Collections.ObjectModel
I am trying to work out a way to group a collection of items like an enum so that I can access them through code else where in my program. i.e I have list of items and sub items
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")
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.
Public Class Store Public Overridable Property Areas As List(Of Area) End Class Public Class Area
[code]....
What's the quickest way to get a total count of shelves for a store? I.e. for a store I get the total count of areas by using Areas.Count Or will I need to loop through each area and tally the count of shelves?
I have an ASP.NET app with lots of textboxes all over the page that need updating at various points through program execution. These textboxes actually belong to a certain class, so for easy updating I thought I could create a Dictionary(Of string, object) and add the control.ID and the control to it and then for updating do something like this:
I need to convert a VB Collection to a modern one, like Dictionary or Hashtable. For my approach, I need the Collection's KEYS. Googling tells me that it's impossible. Re-writing the entire application using new collections is not an option as the application is really old and large (converted from VB6 to VB.Net).Using the old Collection also is not good - as there are new components in development.Converting a - for example - Hashtable to Collection works:
using VBCollection = Microsoft.VisualBasic.Collection; public static VBCollection ToVBCollection(this Hashtable table) {
I've done a little bit of LINQ but I almost exclusively return some elements from a collection based on some criteria. Now I'm trying to do something similar; let's say I have 50 winForm Controls in a collection - I want to set the .Visible property = True based on the controls name.
How would I do that? Below is my failed attempt.
myControls.AsEnumerable.Select( Function (myControl as Control) ( myControl.Visible = (myControl.Name <> "Hidden")) )
I have a ComboBox control with some items added to the items collection in design mode. What I want is when an item is picked from the ComboBox a different value is actually used in the code, instead of what is displayed. I am aware of the DisplayMember & ValueMember properties, but I'm not sure if that is what I need to use. All the examples I found were for bound data.
I have a problem getting the collection of items in the ItemMouseHover event. I want to get the collection of all the items and subitems when the Mouse Hovers in the ListView. I have the property of Full Row select in the ListView.
i have a problem getting the collection of items in the ItemMouseHover event. I want to get the collection of all the items and subitems when the Mouse Hovers in the ListView. I have the property of Full Row select in the ListView.