A Property In A Class Is A Collection Of Objects

Jan 29, 2009

Thought I had got this sorted earlier but unfortunately not. A property in a class is a collection of objects.

[Code]...

View 4 Replies


ADVERTISEMENT

Base Class Collection With Sub Class Objects

Jul 19, 2010

[code]The reason that this is a problem is that this is a collection of EventBase objects, but I'm trying to populate it with child classes instead. For example, I might have a JumpEvent class that inherits EventBase, and this is being put into the EventBaseCollection. That means that value.GetType() returns the type of JumpEvent, which as you might guess does not equal the type of EventBase.The goal of course is to simply loop through all of the various events without having to know anything about the sub-classes. Is there a way to determine the type of the base class so that the OnValidate call will work? Or is this just the wrong way to go about it altogether?

View 2 Replies

Sort Of A Collection Of Class Objects?

Feb 28, 2012

I'm having problems doing a sort of a custom collection. The collection is Device Classes which is a collection of Device Class. My sort does not produce an error but the treeview control shows nothing. I am not sure what I am missing. I'm guessing just a simple sort won't work here but I don't know what I'm missing in my code. Here's the code that creates the collection

[Code]...

Simply sorting the treeview will not work because it throws off the display of related info for a given device in listview controls. The collection itself needs to be sorted before the data is added to the treeview.

View 6 Replies

Adding A List (of Class) Or Collection As Another Class's Property

Apr 2, 2010

I'm looking for a tutorial on how to Adding a list(of Class) or Collection as another Class's Property.What I am after is something like the Columns Collection for the DatagridView control.I would like to add Items in the graphics screen. Where the item list is displayed in the left panel and the selected Item properties are displayed in the right panel.

View 4 Replies

.net - Set An Incrementing ID Property To A Class' Collection?

Nov 15, 2011

I have some nested objects arranged like this:

Process
Persons
Workflows
Tasks

So you have one Process. Then multiple Persons can be added to and multiple WorkFlows can be added Process as well. Multiple Tasks can be added to each WorkFlow but I need a way to tie which Person is doing each task. I basically need a way that for each Person added to the Process it, in it's constructor, assigns a Person.ID property that can then be assigned into each Task's PersonID property...

Dim myProcess as New Process()
Dim myPerson as New Process.Person()
myProcess.AddPerson(myPerson)

[code]....

View 2 Replies

Retrieve A Property Of A Class As A Collection?

May 26, 2012

I'm working on a small project and got into some troubles trying to keep it OOP.I have a global variable:

Public Stations As New Microsoft.VisualBasic.Collection()
And 2 classess: Station & Unit:
Public Class Station

[code].....

View 1 Replies

Alter Items Added To Generic Collection (as Property Of Custom Class)

Jun 19, 2009

I have several custom classes in a VB.NET (VS2008) project which are related to each other through generic list collections. The lower tier classes refer directly to some of the parent classes (to make it easier to refer backwards up the chain). My question is, is it possible to add the reference to the parent class when the item is added to a collection, when that collection is a property?

Below is some sampling of code to illustrate.
Public Class FlexServer
Private m_FlexLicenses As List(Of FlexLicense)
Private m_Modules As List(Of FlexModule)
Public Property FlexLicenses() As List(Of FlexLicense)
[code] .....

In the code above I have the FlexServer class which refers has two lists as properties, one for FlexLicense and one for Modules. The FlexLicense class has a property to refer back to the FlexServer class that "owns" it. In order to update this property in code, I have to add the FlexLicense to the FlexServer.FlexLicenses list AND set the FlexLicense.FlexServer property. What I am looking for is, is there a way (in the property definition or wherever) to both add the item to the list and alter it at the same time?

View 1 Replies

Class Collection Property - Method - Allow For An Employee To Be Assigned More Than One Work Location

Jun 17, 2011

I am experimenting with a transition from my application built in VB6 to vb.net. I know, about time. At the same time, i am making changes and improving upon the original. One area that I am working on is within my employee class. very standard class, nothing fancy. One change I want to make though is allow for an employee to be assigned more than one work location. Employee has (is assigned) Stores. In reading about collections, it appears they are different in .net (as they should be), but I don't know what the sytax changes will be to implement my changes.

View 6 Replies

Sum The Properties Of Two Members Of A Collection Without Doing It Property By Property?

Aug 8, 2011

I've reviewed the links that were offered and don't find an answer. Neither has a lot of searching helped, probably because I can't think of a reasonably short way to ask the question. I hope that I've at least found the proper forum and category.

In my VB 2010 code, I've defined a structure that has about 30 elements. I want to sum the properties (they are all singles) of two members of the corresponding collection. I understand that I can do something like:

member1.property1=member2.property1+member 3.property1 for the entire set of properties of member2 and member3 to produce a completely defined member1 What I wonder is whether or not there is a way that uses fewer lines of code - I know that I can't do:member1=member2+member3, for example.

View 7 Replies

.net - Inheritance And Collection Of Objects?

Oct 21, 2011

we have 3 classes:Class S, class A, class B / A and B inherits S.A has a property A1 and B has a property B1.we also have a collection of objects that has A and B objects.ex.

Dim c as Collection = new Collection
c.add(new A)
c.add(new B)

Now we want to make a general object that will read from the collection.

ex .
Dim obj as S

how can we cast obj in order to see properties A1 or B1 according to the class;

View 1 Replies

Collection Of Objects Of Different Classes?

Dec 28, 2011

suppose I have a collection of objects of different classes (like controls in a form), and all of their classes have a MyMethod extension method. How do I have the appropriatemethod be called for each object, depending on its type?or example,

For Each ctrl In Me.Controls
'call ctrl real type's MyMethod
Next

[code]....

View 6 Replies

Collection Of Objects With A Unique Key

Jan 25, 2011

i've researched and written a generic class (all my objects are the same structure) and i'm was just working on the collection using a hash table but i've just read a comment within (url...) in this forum...that we shouldn't use hashtables at all with vs2008.i actually need and object collection that contains other object collections within them.the application i'm trying to write is relatively simple (but i'm new to vb.net)it keeps track of the time for weight lifting training/workouts.a workout consists of 'say' a bench press, military press, curls, dead lift, etc within the "bench" you have 1,2, or 3 sets (how many times you do "the bench", within a set you have 1,2,3 or 4 lifters, each lifter does reps.then it starts over with military press..i guess i could base it on a treeview type structure (with parent child type relationships) but i usually think in terms of collections it appears that a collectionbase has no key and i'd have to keep track of them on my own...

View 2 Replies

Lifetime Of Objects In A Collection

Nov 16, 2010

I'm trying to figure out the lifetime of the tmpTabPages in the following bit of code. Lets assume the form has an empty TabControl named MyTabControl, that there's a collection of strings called NameCollection.

[Code]...

View 4 Replies

Run A Method On All Objects Within A Collection?

May 29, 2009

So I have a collection of Razzies created from a Collection of Bloops. I retrieve this collection using a Linq query. Reference:select-certain-properties-into-another-object for the query.I would like to know if it is possible to run a method on all of the newly created Razzies before returning the collection, or even right after, just without using a for-loop.

I tried ths:
Dim results = From item In bloops _
Select New Razzie() With _

[code].....

View 6 Replies

.net Collections: Copy Objects From One Collection To Another?

Nov 24, 2011

I'm implementing a customized Graph algorithm in vb.net, and I'm having the following problem:

Supose the code:

dim col as new collection
dim myC as new system.collections.genericList(of myClass)
dim obj1 as new myClass
dim obj2 as new myClass

[code].....

'In the next statement, the myC2 inside col collection will be decreased to contain 'only obj1, like myC. I supose this is for myC and myC2 contains only a pointer to 'objects obj1 and obj2 as well col contains pointers to myC and myC2 myC.remove(obj2)'The problem is that I have to only copy myC to myC2, like a ByVal argument in a function,'instead a ByRef argument, in order to mantain a copy of objects in myC2 while these 'objects should be removed from myC. How should I do it?

View 2 Replies

Creating A String From A Collection Of Objects?

Oct 4, 2010

I have a question. I have a class of Cars that I need to display in a simpli-ish string if they will be sold or not base on their number.

[Code]...

I'd like to display a simple string like this:Cars to be sold: 1, 3-5, 7-8, 11, which is based of the .Sell value.Is there some kind of heuristic to create this kind of string in .NET or is it just a bunch of for/each and if/then and redimming of arrays?

View 2 Replies

How To Create Accumulator For Collection Objects

Apr 23, 2012

I am trying to maintain a total for multiple collection objects in a class. When I create a new object, it resets the total to zero, only adding the current value being passed to the function. I have tried to use a static variable, create a second variable to hold the old total while adding the new value. The base class holds the total value, while the sub class creates the new object that holds information. I am passing the new value to a function in the base class adding the new value to the total when each new record is created.

[Code]...

View 1 Replies

Lazy Loading On A Collection Of Objects?

Mar 6, 2009

i have a sql query that can bring back a large number of rows via a DataReader. Just now I query the DB transform the result set into a List(of ) and data bind the Grid to the List.This can result occasionally in a timeout due to the size of Dataset. I currently have a three teir setup where by the UI is acting on the List of objects in the business layer.

View 3 Replies

Pass Collection Of Objects To BackgroundWorker?

Nov 19, 2010

I have an object of type Dictionary(Of Int16, Polygon) and which contains sometimes up to 15 or so Polygons that i am creating bitmap files with the Polygon. This can take like 20 seconds sometimes so i was trying to pass the full Dictionary to background worker as an argument but i get an issue when trying to access each individual Polygon inside of the Dictionary because the Polygons still belong to the UI thread. How can I access the Polygons inside the Dictionary with the backgroundworker?

Dim worker As New BackgroundWorker
AddHandler worker.DoWork, AddressOf MeasurePolygons
AddHandler worker.RunWorkerCompleted, AddressOf WorkerCompleted
worker.RunWorkerAsync(PolygonCollection)

that is how im calling the thread. PolygonCollection is the Dictionary(Of Int16, Polygon) that contains all the polygons that i will be creating a bitmap file out of.

View 9 Replies

SQL Command Objects Paramaters Collection

Sep 16, 2010

I was just curious as to whether after you have added all of the Parameters to the SQL Command Parameters Collection. Is there a convenient way to iterate or loop through the Parameters and make Assignments to the SQL Command Parameters Values Property?

View 2 Replies

Call Method Base Class In Program Passing Sub Class Objects?

Apr 22, 2012

Base class has one field to hold numeric balance value. With 2 methods that accept arguments for adding and subtracting the new input calculating new balance. Sub class has four fields dates, transaction, memo and amount.I have a deposit form, and withdraw form. Each time one transaction is entered it creates an object with sub class fields, then adds to the account collection. My problem is not understanding how to call the deposit/withdraw method and pass the current transaction amount back to the base class to alculate the new balance. Does anyone have any links to information/tutorials on how to perform something like this? As you can see with my code I have tried various different approaches without any success.

[Code]...

View 5 Replies

.net - Binding A Collection Of Objects To A ComboboxColumn In A DataGridView?

Jan 24, 2012

I have a GUI which allows the user to select a report to view/edit. When the user selects a report, it shows the Items in the report. The Item has many properties - most of which are binding properly. One of the properties is Owner, and this is bound to a ComboBoxColumn.

Report

Items

Owner

I have done something very similar to this a few times and had no problems when I set the DataPropertyName, DataSource, ValueMember, and DisplayMember. The only difference is that this time instead of the Item type having an OwnderID it actually has an instance of the Owner object.giving the items bound in the list a self-referencing property that allows them to return themselves for the purposes of setting the ValueMember.However, When I bind it this way:

OwnerColumn.DataPropertyName = "Owner"
OwnerColumn.DataSource = ownersBindingSource1
OwnerColumn.ValueMember = "Self"
OwnerColumn.DisplayMember = "OwnerName"

I get a lot of errors like: Unable to cast object of type 'System.String' to type 'Owner'.

and:

The following exception occurred in the DataGridView:

System.ArgumentException: DataGridViewComboBoxCell value is not valid.To replace this default dialog please handle the DataError event.I was able to get around some of these errors by binding it like this:

OwnerColumn.DataPropertyName = "Owner"
OwnerColumn.DataSource = ownersBindingSource1

and also by making the ToString function on the Owner display the OwnerName property. This seems pretty hacky though - and I think I'm misunderstanding something fundamental as it still does not function properly.

View 1 Replies

Collection To Place These Objects In For Easy Reference?

Nov 11, 2011

I have an error while using a collection that has been stumping me for years.I wrote a class to allow users to write equations in a txt file using RPN (stack based notation).The class runs through a select statement while reading the equation and then ends up with a final number as the answer. I have a collection to place these objects in for easy reference. For whatever reason I get random object reference not set to an instance of an object errors when there is nothing in the program that would remove objects from the collection, kill objects, or change the collection in any way. It is possible for one thread to call the calculate function while another thread calls the CurrentValue property. I'm not sure if this could be causing the error, but once it happens I get an error every time the program enters that code until I run out of memory.

[Code]...

View 4 Replies

Store Objects With Key In Some Sort Of Collection/Dictionary?

Jun 10, 2012

I need to Store Objects with Key like:

Key: <Fontname & FontSize> / Object: <Font Object>

Example content:

ArialRegular8 | <Corresponding Font Object>
ImpactItalic10 | <Corresponding Font Object>
TimesRomanRegular12 | <Corresponding Font Object>

These font types come from an external library, the real type is DocumentFont, I prefer not to store just values and recreate the font object later, so I need to store the object, and i want to be able to call Contains() later without looping. like for example Dictionary (of T Key, T Value), is this the best option? Also, to be able to call Contains(), i will have to overload function Contains() using an Interface or this is already built-in in some Collections / Dictionaries when using a String as Key?

View 3 Replies

Class That Inherits Another Class In Which There Are Objects That Are Disposed In Dispose Procedure

Feb 14, 2010

If I have a class that inherits another class in which there are objects that are disposed in the dispose() procedure, do I use mybase.dispose? ex Class A inherits Class B. [code]

View 2 Replies

Place Dynamically Generated Objects In An Array (or Collection)?

Apr 11, 2011

I created a custom class for a custom object. I instantiate like so[code]...

Now, I have two problems. First, right now this is just overwriting the same object properties, again, and again. I need to somehow dynamically name the object. Then, I need to place these objects in an array so I can iterate through them...

View 1 Replies

VS 2010 Multi-threaded But Using A Global COLLECTION Of Objects?

Mar 19, 2012

I've got a multi-threaded app - that is using a global COLLECTION of objects.I'm starting to think that objects - when copied to objects - are really just reference pointers to the "single object" in memory - as they would be in JAVASCRIPT (too many languages At any rate - this code - when taking the object from the collection to work with is it making a new object to play with or is it working the single object that actually resides in the collection?

[Code]...

View 16 Replies

Passing List / Collection From Class To Class

Apr 28, 2009

I seem to have problem with passing a collection/sorted list/ list of strings from one class to another.I am using property procedure to pass it, however nothing is sent to another class. There isn't any error messages either.[code]

View 3 Replies

Use A Custom Collection Derived From CollectionBase To Store Our Business Objects

Feb 26, 2009

We use a custom collection derived from CollectionBase to store our Business objects

[Code]...

View 3 Replies

.net - Make A Class Property Behave Like The Checked Property On RadioButton?

Jun 1, 2012

I have a very simple class that holds a few public properties - ID, Text, Colour, etc. and a Boolean called 'SelectedItem'. Just like the Checked property on RadioButtons, only one item can have its SelectedItem property set to True within a particular group. Note: there will be several separate groups (lists), each allowed to have only one item with SelectedItem = True.

My first thought was that I would probably just have to handle everything outside of the class, setting SelectedItem to False for every other item in a particular list when another item was selected. But that seems rather inelegant to me. So I've been trying to think of how this might be done within the class. For example: could I perhaps have a private string property called say "GroupName" - set in the New sub when adding a new instance of the class - and then use a private shared method to set every item's SelectedItem property to False, provided the item has the same GroupName as the newly selected item? I would have a go at doing this but I have no idea how to enumerate every instance of a class from within that class, or whether that's even possible. Is it? Or is there another (better) way to achieve my goal? Here is a cut-down version of what I've got so far:

Public Class ResourceItem
Public ID As Integer
Public Text As String[code]....

As can be seen: instead of instantiating a new ResourceItem and passing that as an argument to the manager's Add procedure, I'm simply passing the details of the new item and the procedure is creating the item from those. I don't know whether this is a good or bad idea - please advise - but I've done it because I couldn't figure out how to make the SelectedItem property only writeable by the manager, so I wanted to avoid having directly accessible objects that could have their SelectedItem property set to True without it deselecting all the other items in the same group. Of course that still leaves the possibility of setting a variable to one of the manager's list items and setting it from there, so I would still like to know how I could prevent that, if possible.

UPDATE: I didn't use the code above in the end, deciding instead to go with Cyborgx37's solution - which seems to work perfectly well for me despite the warnings about best practice. I also realised I would need to use the same class in another scenario where multiple items could be selected, so it was easy to add a Boolean property to the manager to enable that.

View 2 Replies







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