Looping Through Generic List?

Apr 30, 2010

I want my loop to loop until it reaches the last string in my generic list. I know I could simply insert the last index of the list as an integer but I want to be able to use this if my list grows too. How could I achieve this?

View 5 Replies


ADVERTISEMENT

.net - Creating A Generic List Of A Generic Type

Jun 30, 2011

I am trying to create a list of a generic type in vb.net 2.0 framework.
This is the generic type definition:

Public Class GenericParamMap(Of T)
Public Sub New(ByVal pParamName As String, ByVal pPropValue As T)
mParamName = pParamName

[Code]....

The compiler does not allow a "T" in the method's parameter because it's not defined, but I'm not sure how or where to define it. I thought it was okay to have a generic method definition.

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

Get Type Of Derived Generic List Class From List Item Method?

Mar 23, 2011

Public Class notifierMain
Public Class Contacts
Inherits List(Of row)
Public Sub New()

[code]....

When I debug this winforms application I get curType = "notifier.notifierMain+Contacts+row" I want to the Validate function to know it is in MyContacts. How do I do this?

View 3 Replies

.net - Returning A List Using Entity Framework, 'System.Collections.Generic.List Cannot Be Converted To '1-dimensional Array

May 3, 2012

i have issue returning a list in a web method. here is the code

<WebMethod()> _
Public Function getTags(para_parents As String) As List(Of getTypeDetailsByParentName_Result)()
Dim context As New PPEntities

[code]....

the error is

Value of type 'System.Collections.Generic.List(Of SaftyonRoad.getTypeDetailsByParentName_Result)' cannot be converted to '1-dimensional array of System.Collections.Generic.List(Of SaftyonRoad.getTypeDetailsByParentName_Result)'

View 1 Replies

Pass Generic List To A Function That Has A Custom Defined List

Apr 7, 2011

it seems always at this time I cant figure out how to do something maybe it has something to do with lunchtime.

Im having trouble using a method that is defined by an outside company

This is a link to their integration guide:

[URL]

This is their documentation for the class Im trying to use

OrderQueryWebService Class

This class is for SID in particular and is made for use with the notification methods. This is for the Order Query Web Service specifically, allowing clients to return the status of transactions for their merchant, whenever they want to.

Methods
/ <summary>
/ Pass through the variables required and receive a list of Transaction
objects showing transaction status

[Code].....

The MerchantCode, the MerchantUsername, the MerchantPassword are all good the List is a custom type called SetComHash.Transaction

Everytime I try adding a string to the list such as the transactionNumber and some other values it gives me a type error:

"Value of type string cannot be converted to 'SetcomHash.Transaction'

View 13 Replies

.net - Sort Generic List Based Upon A Different List?

Oct 29, 2010

What would be the fastest way to sort a list that contains a list of objects, based upon another list? An example follows:Say I have multiple lists of employees. Each individual list has a common property value, say "Department". So I have a list of employees, in one list they all have the department string value of "Sales". In another list all the objects have a department value of "Finance". These lists of employees are then contained in a list which holds them all.

I have a second list, which should drives the sort order of the employee lists. The second list simply contains a list of strings like, "Finance", "Sales", "IT" and so on. I'd like my lists of customers to be sorted in the order of "Finance", "Sales", etc.I'm using VB.NET in .NET 2.0

View 1 Replies

Looping Thorugh A List Box?

Jul 26, 2011

I am trying something new. I now how to loop through items in a list box but this is where I am stuck. I am looking to loop through my list box and send a email to each email within my list box.I am unsure if I am using the right loop or not. I am using a for loop. Here is what I have so far in code:

Dim smtpserver As New SmtpClient
Dim mail As New MailMessage
smtpserver.Credentials = New Net.NetworkCredential(txtUsername.Text, txtPassword.Text)

[code].....

View 4 Replies

Looping Through A List For A Spellchecker?

Jun 27, 2012

I am looping through a list for a spellchecker in vb.net (using vs 2010). I want to go through a wrongly spelled word list. Each time the code picks the index that's one higher than the index of the last checked word.

In my version of notquiteVB/Pythonese I think it would translate something like:

(start loop)
dim i as Integer = 0
dim word as String

[Code]....

But this doesn't work at all...when it gets to the last item in the list and reaches 'word = ' it throws the error of 'out of range -- must be less than the size of the collection'.

How do you get the last item in a list? Maybe lists aren't what VB uses for this kind of thing?

View 1 Replies

Looping Through Array List?

Nov 15, 2009

I'm making a card game and I want to try and design my own card deck.

Dim X As Integer
Dim currentCard As Integer, currentCard2 As Integer
Dim RandomNumbers As New Random()
Dim NumberofCards As Integer

[code]....

I started a basic vb.net class for my fall semester of high school, and although I've learned a lot, my goal since the start of the semester has been to do this. I realize there are simpler way of assigning card values than writing 52 if then statements, but I'm planning on doing other things with the statements. As you can see, my main plan of action is to generate a random number for each card, loop through the array list to make sure the random number representing that card hasn't been assigned before, use the value to select the card, and then add the randomly selected number to the array list so it won't be used again (non-repeating random numbers).

1) I'm trying to represent all the numbers with Numberlist.Item(X) and that doesn't work because either a) x represents any one number or b) x always represents only 0, which means it only checks the first number.

2) I think I've read something about using this method for generating random numbers in a loop, that it doesn't work for some reason.

View 1 Replies

Looping With List(of Objects)

Oct 15, 2009

I have a procedure in VB.net using VS.net 2008 which will get the list of Orders and build a XML file with the list of Orders as shown in the code below: As the number of Orders is getting huge, I want to build the XML file for every 500 Orders

[Code]....

Instead of building XML for all the records I want to create XML for each 500 records. I tried the following code and it is throwing an error saying Expression is of type Orders which is not a collection type.

[Code]....

View 4 Replies

Generic TypeOf Operator - See If List Is A List(Of T) Variable - Error: "Type Expected"?

Jan 5, 2011

Dim x = GetType(List(Of )) 'valid statement
Dim list As New List(Of String)

Now I want to see if list is a List(Of T) variable: Dim isList = TypeOf list Is List(Of ) On the last line I get a compile error: "Type Expected". Is there any cheap-performance TypeOf operator alternative for generics?

View 2 Replies

Error - Red "List" Says Too Few Type Arguments To System.Collections.Generic.List(Of T)'

Mar 12, 2009

I have converted c# .cs to vb:= I have 6 errors on:

Red "List" says Too few type arguments to system.Collections.Generic.List(Of T)'
Orange "Calendar" says Value of type 'System.Windows.Forms.Control.ControlCollection' cannot be converted to 'Form1.Kobush.Windows.Forms.Appointment'.

[code]....

View 6 Replies

Looping Through A List Fill A Table?

Jun 22, 2010

I am trying to move through a list "TodaysCard" and print the TimeOfDay.ToString into the first column of every row and to only create the amount of rows that are needed. But am a bit of a novice when it comes to this and can only get it to display the TimeOfDay.ToString value for the first item in the list over and over again. Just wondering how I can get it to iterate through each item properly.

For Each Race In TodaysCard
With (Race)
Try

[Code].....

View 1 Replies

Looping Though A List Or Collection Of Controls Available In The Development Enviroment?

Apr 12, 2009

How can I find a List or Collection of User Controls available within the development enviroment and dynamically add them to a combox by their Name Property. I am looking for something along the lines of:

View 4 Replies

Asp.net - Find The Max Id From A Generic List?

Oct 13, 2011

i m getting a collection of data in list's object. And from this list i want to get the maximum id.`

Dim objinfo As List(Of AlbumInfo) = objPhotos.GetPhotos_Alb_ID(Me.ModuleId, hdd_AlbID.Value)
Dim Photo_Image As String = ""
Dim str As String = Photo_Image & fu_Photo.PostedFile.FileName.Substrng(fu_Photo.PostedFile.FileName.LastIndexOf("."))

[code]....

this returns the "0"th positions id from Convert.ToString(objinfo.Item("0").Photo_Id + 1)but i want to get the last item's id.

View 17 Replies

C# - Sum Of A Column Of Generic List?

Jan 5, 2011

i have list of string like this :

Dim totalPrice As New List(Of Integer)

how can i get sum of column(0) (C# or VB) ?

View 4 Replies

Generic List, Add, And Same Values?

Jan 17, 2011

<div class=PhorumReadBodyText>Hi, I have a problem with adding of items to generic list, problem is when I insert 1. item to the list, everithing is ok, but if I insert second item, first and second has same values.

code looks like that (asp.net 4.0): </div> <div class=PhorumReadBodyText> </div> <div class=PhorumReadBodyText>Partial Class _Default
Inherits System.Web.UI.Page

[Code]...

View 1 Replies

How To Add Items To Generic List

Jan 17, 2011

I have a problem with adding items to generic list, problem is when I add 1. item to the list, everything is ok, but when I add second, first and second has the same values...

This is code (asp.net 4.0):
Partial Class _Default
Inherits System.Web.UI.Page
<Serializable()>
Public Class Product
Shared Property Material As String
[URL]

View 7 Replies

Loop Through Generic List

Aug 26, 2009

In my VB.net application I am populating my customer object and looping through it as shown below.As there are thousands of customers, I want to do it 500 customers at a time.Is there anyway I can have one more For loop to process 500 customers at one shot in vB.netI am not using LinQ as the database is Oracle.[code]

View 2 Replies

Searching A Generic List

May 14, 2009

I have been reading extensively about searching generic lists in VB.NET with the usage of delegates.However, I still cannot seem to grasp how to achieve what I want to, which I believe is frustratingly simple! I have a list populated with instances of an object with three parameters (fields/ variables).When I receive a new object to add to the list I want to search the list for the "layer" field.If the field matches then I will replace that row (object) in the list with the new object, if no match is found then I will add it to the list. [code]

View 3 Replies

Splitting A Generic List?

Jun 11, 2011

i have a generic list of type datarow.i have to split this list at an index and then use both parts of the list.

View 2 Replies

Linq To Objects - (C#) Creating A Dictionary From An Existing List Without Looping?

Aug 31, 2011

I don't know if this is doable, maybe with Linq, but I have a List(Of MyType):

Public Class MyType
Property key As Char
Property description As String
End Class

And I want to create a Dictionary(Of Char, MyType) using the key field as the dictionary keys and the values in the List as the dictionary values, with something like:

New Dictionary(Of Char, MyType)(??)

Even if this is doable, internally it will loop through all the List items, I guess?

View 3 Replies

.net - GroupBy 2 Values In A Generic List?

Aug 18, 2010

I'm using VB.NET on Framework 2.0. I'm looking to quickly group a Generic List<> by two properties. For the sake of this example lets say I have a List of an Order type with properties of CustomerId, ProductId, and ProductCount. How would I get the average of ProductCounts grouped by CustomerId and ProductId in VB.NET ?Unfortunatly I cannot do this at DB level (which would have been easy). Also I cannot use LINQ or Lambada as Im on Framewwork 2.0. So I need to do this at application level in VB.net. The list is returned to me sorted by CustomerId and ProductId so I guess with a few loop sI should be able to create a average value for but there must be a cleaner way to do this?

View 1 Replies

.net - Iterating Through Generic List Of String?

Jan 28, 2012

I have the follow code in my program where I hit a SQLCe database to append the results into a list. That part works, but instead of exiting the function 'QueryDB' it goes to the else statement and runs the function again, which will return a null value. I designed it this way becuase I wanted to check to make sure the database is open before I try to execute the SQL statement, and if it's not open, call the method to open it and run through the function again.

[Code]...

View 1 Replies

.net - Sort Generic List On Two Or More Values?

May 15, 2009

We have a generic List(Of Product) that must be sorted on two or more properties of the Product class.

The product class has the properties "Popular" numeric (asc), "Clicked" numeric (desc), "Name" string (asc). In order of naming the properties we want the list to sort.

How can it be sort with an lamba statement? If have found to sort the list based on one property.

View 4 Replies

Add Custom Class To A Generic List?

May 10, 2010

I created two classes. One class is StudentClass and the other is HomeroomClass. The HomeroomClass contains a readonly property as a generic list of the StudentClass. [code]...

View 6 Replies

Asp.net - Linq To Sql Convert To Generic List In .NET?

Jul 2, 2009

I am trying to learn some VB.NET for my coo-op that starts next week, and for that reason i took my portfolio web site that is on C# and just started to converting it to VB.NET to get familiar with the syntax.

I am sure my problem is simple however i have a hard time solving it. I am trying to grab data with the linq query and then return it as list to bind to the Repeater.I have the following function:

[Code]...

And it would work fine. However if I try to use ToList() in VB.NET i am getting error that it cannot convert it from ling to sql List to the generic list. How do i do this convertion in VB.NET ? or maybe there is another way ?

I am decent when it comes to C# however somewhat lost with the VB.NET syntax.

View 1 Replies

Better Way Of Filling A Generic List From A SQL DataAdapter?

Apr 11, 2009

I have an existing application that uses Active Record for its data retrieval. It's in VB.NET (first time I'm doing VB.NET; I usually work in C#). And I'm building a method to return a List(Of T) of an object. The current pattern uses a SQLDataAdapter to populate a datatable. I COULD add the record to the List(Of T) as I fill the datatable, but there HAS to be a better way to do this.

View 1 Replies

C# - Get Values From An Enum Into A Generic List?

Nov 21, 2011

I don't know how to convert the following line from VB to C#:

Dim values As New List(Of T)(System.Enum.GetValues(GetType(T)))

My version doesn't work:

List<T> values = new List<T>(System.Enum.GetValues(typeof(T)));

The best overloaded method match for 'System.Collections.Generic.List.List(System.Collections.Generic.IEnumerable)'
has some invalid arguments

The constructor-parameter doesn't take it that way - what cast (or else) am I missing?

For clarification: It is wrapped up within the following generic method

public static void BindToEnum<T>()
{
List<T> values = new List<T>(System.Enum.GetValues(typeof(T)));
//...
}

View 2 Replies







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