By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,652 Members | 1,682 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,652 IT Pros & Developers. It's quick & easy.

How do I retreive a custom object's properties from an arraylist

P: n/a
Ric
Please forgive me if i dont explain this situation correctly. i'll try
to do my best.

because the arraylist.add method only accepts one argument, i created
an object with several public properties.

AddElement.vb (compiled and saved in Bin folder)
' VB Document
Imports System

Namespace myArrayObject

Public Class AddElement
Private _pName as String
Private _pType as String
Private _pSize as Integer

Public Property pName as String
Get
Return _pName
End Get
Set
_pName = Value
End Set
End Property

Public Property pType as String
Get
Return _pType
End Get
Set
_pType = Value
End Set
End Property

Public Property pSize as Integer
Get
Return _pSize
End Get
Set
_pSize = Value
End Set
End Property

End Class
End Namespace

Then I imported this object into a codebehind file. my goal was to
instiate the object's properties and set them accordingly

dbArraylist.vb (codebehind file with command event sub)

Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HTMLControls
Imports myArrayObject
Imports System.Collections
Imports System.Data
Imports System.Data.SqlClient
Imports dbComponent

public class myALComponent
Inherits Page
Protected WithEvents lkID as linkbutton, lblAnswer as label
sub getActivityList(s as Object, e as CommandEventArgs)

Dim ID As Int32 = Int32.Parse(e.CommandArgument)

Dim myArrayList as new ArrayList, myParameter as new AddElement,
objItem as object
myParameter.pName = "@ID"
myParameter.pType = "ID"
myParameter.pSize = 0
myArrayList.add(myParameter)

myParameter.pName = "@ID2"
myParameter.pType = "ID2"
myParameter.pSize = 2
myArrayList.add(myParameter)

response.write("<br>myArrayList Count : "& myArrayList.count &
"<br>")

for each objItem in myArrayList
response.write("<br>AL : <br><li>" & objItem.toString)
next
end sub
end class

the aspx file passes the commandName and commandargument (= 1) via a
linkbutton. ive tested the link and it works, but im not using the
commandargument yet. my obstacle now is retreiving the property values
stored inside the object inside the arraylist. right now, i get
'myArrayObject.AddElement' as the objItem in myArrayList. that makes
sense because that is the object inside the arraylist. but, i want to
get the pName(string), pType(string) and pSize(integer) which are
public properties of the AddElement object from the
myArrayList(elementNumber). i tried casting it toString (result :
myArrayObject.Addelement) and cType(myArrayList(0), string) result :
can not cast error. thx for the help in advance.

ric
Nov 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi, Ric,

Try to cast the elements of the ArrayList to the type of your class, i.e.

Response.Write(CType(myArrayList(0), AddElement).pName)

Hope thid helps
Martin
"Ric" <dj****************@yahoo.com> wrote in message
news:78**************************@posting.google.c om...
Please forgive me if i dont explain this situation correctly. i'll try
to do my best.

because the arraylist.add method only accepts one argument, i created
an object with several public properties.

AddElement.vb (compiled and saved in Bin folder)
' VB Document
Imports System

Namespace myArrayObject

Public Class AddElement
Private _pName as String
Private _pType as String
Private _pSize as Integer

Public Property pName as String
Get
Return _pName
End Get
Set
_pName = Value
End Set
End Property

Public Property pType as String
Get
Return _pType
End Get
Set
_pType = Value
End Set
End Property

Public Property pSize as Integer
Get
Return _pSize
End Get
Set
_pSize = Value
End Set
End Property

End Class
End Namespace

Then I imported this object into a codebehind file. my goal was to
instiate the object's properties and set them accordingly

dbArraylist.vb (codebehind file with command event sub)

Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HTMLControls
Imports myArrayObject
Imports System.Collections
Imports System.Data
Imports System.Data.SqlClient
Imports dbComponent

public class myALComponent
Inherits Page
Protected WithEvents lkID as linkbutton, lblAnswer as label
sub getActivityList(s as Object, e as CommandEventArgs)

Dim ID As Int32 = Int32.Parse(e.CommandArgument)

Dim myArrayList as new ArrayList, myParameter as new AddElement,
objItem as object
myParameter.pName = "@ID"
myParameter.pType = "ID"
myParameter.pSize = 0
myArrayList.add(myParameter)

myParameter.pName = "@ID2"
myParameter.pType = "ID2"
myParameter.pSize = 2
myArrayList.add(myParameter)

response.write("<br>myArrayList Count : "& myArrayList.count &
"<br>")

for each objItem in myArrayList
response.write("<br>AL : <br><li>" & objItem.toString)
next
end sub
end class

the aspx file passes the commandName and commandargument (= 1) via a
linkbutton. ive tested the link and it works, but im not using the
commandargument yet. my obstacle now is retreiving the property values
stored inside the object inside the arraylist. right now, i get
'myArrayObject.AddElement' as the objItem in myArrayList. that makes
sense because that is the object inside the arraylist. but, i want to
get the pName(string), pType(string) and pSize(integer) which are
public properties of the AddElement object from the
myArrayList(elementNumber). i tried casting it toString (result :
myArrayObject.Addelement) and cType(myArrayList(0), string) result :
can not cast error. thx for the help in advance.

ric

Nov 18 '05 #2

P: n/a


thx again martin for the quick help. it worked perfectly.

ric

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.