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


ADVERTISEMENT

.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

.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

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

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

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

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

.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

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

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

Calling Collection(Of T) First() Method

Jul 6, 2009

I am having some problems calling the First() method of the System.Collections.ObjectModel.Collection(Of T) class. My front-end web application is VB.Net 3.5, and the data access layer is C# 3.5. Here is pretty much the sample code I have:

[Code]...

View 3 Replies

Using Objects In A Method?

Apr 16, 2012

I have some procedures I want to store in a module and call up to use in the form.My problem is that the radio buttons are not being transferred into the module. I think I need a line of code at the beginning of the method so it has access to all the objects created in the form.

The error I am getting is:[rb#] "is not declared. It may be inaccessible due to its protection level"

rb# are radio buttons that are being used in the main form.form:

[Code]...

View 3 Replies

.net Dictionarybase Collection Method Clear?

Nov 30, 2009

I need to clear a dictionarybase collection have tried the below mentioned method but it gives me an error... any help please?? ( in the Public sub MClear....) here's the code:

Imports System.IO
Public Class IPAddresses
Inherits DictionaryBase

[code]....

View 1 Replies

MSDN - Collection(Of T).RemoveAt Method

May 25, 2012

The MSDN page for this method says this: ArgumentOutOfRangeException. index is less than zero.-or-index is equal to or greater than Count. That doesn't make any sense, surely it should be "index is equal to or greater than (Count - 1)" Since index is zero based. I need to know since I'm Overriding the RemoveItem method for a Class that Inherits Collection(Of T).

View 6 Replies

Dereferencing Objects - Make CopiedCollection A True Copy (not A Reference) To The Listbox1.Items Collection?

Jun 30, 2010

Okay I've been wondering about this for a while now, but whenever you assign variable values to objects they tend to just become references to the original object

For example:

Dim copiedCollection As ListBox.ObjectCollection = ListBox1.Items
For Each L As String In copiedCollection
If L = "Goodbye" Then ListBox1.Items.Remove(L)
Next

As soon as it encounters the string "Goodbye" and removes the item from the listbox, the program will throw an error saying the the collection (copiedCollection) has been modified. How can I make copiedCollection a true copy (not a reference) to the Listbox1.Items collection?

View 14 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

.net - Can The Select Extension Method Project To A List Of Instantiated Objects

Mar 24, 2011

I have two lists declared as follows:

Dim lstDBItems As New List(Of DBItem)
Dim lstAppItems As New List(Of AppItem)

I am trying to do something like this:

I've a function which returns List(Of AppItem):

Function GetAppItems() As List(Of AppItem)
'...
End Function

In the above function I populate lstDBItems and then write the return statement like follows:

Return lstDBItems.Select(Function(x)
dim oItem As New AppItem()
oItem.Property1 = x.DbProperty1

[Code]....

The weird thing is the code compiles, but on rumtime I get a type case error.

View 3 Replies

Two Objects That Are Raising Some Events - Pressing A Button - Raise A Custom Event, Then Execute A Method And Then Close The Form

Mar 30, 2011

Problem that you may have when dealing with two objects that are raising some events. Here, to make it obvious, I am closing the form, but the problem can be experienced with any other 2 classes event. First, what is the problem !

Let suppose that by pressing a button, you want to raise a custom event, then execute a method and then close the form

In that case, you may use a code similar to this

Event BeepIt()

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
RaiseEvent BeepIt()

[CODE]...

View 14 Replies

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

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

Method Calls On Objects That Aren't "Guaranteed" To Be Instantiated?

Sep 10, 2010

I recently wrote a section of code wherein upon finishing, I received a warning from the compiler telling me that one of my variables is being used before it is assigned a value. In practice, the method call on this object will never be made without the object being instantiated beforehand. Here is the snippet of code

Try
fs = New FileStream(fileName, FileMode.Open)
Dim PolarMatrix As PolarMatrix
PolarMatrix = DirectCast(bf.Deserialize(fs), PolarMatrix)

[code]....

I assume I'm receiving this warning because the first line in the Try section may be the line to throw the error, and the Object will never be instantiated. FileName though, is a variable being passed to this method which has already been checked for errors, so it is guaranteed to be correct. The error I'm expecting to perhaps be thrown comes during the deserialization.

So my question: When warnings are given on objects that the compiler thinks may not have been instantiated, does this overrule the user knowing that a problem will never arise on that line? Is it sometimes necessary to add code simply to appease the compiler?

View 1 Replies







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