Thursday, March 22, 2012

listbox +array+object ??

helllo
i currently have userobj that i am storing in a arraylist, i want to bind it to a list box and display the information but i am having no luck ..can some one help code below

PublicClass userObject

'defualt constructor

PublicSubNew()

EndSub

'private properties

Dim uFnameAsString

Dim uLnameAsString

Dim uMnameAsString

'additional constructor

PublicSubNew(ByVal lnameAsString,ByVal fnameAsString,ByVal mnameAsString)

uLname = lname

uFname = fname

uMname = mname

EndSub

'public properites

PublicProperty firstName()AsString

Get

Return uFname

EndGet

Set(ByVal valueAsString)

uFname = value

EndSet

EndProperty

PublicProperty lastName()AsString

Get

Return uLname

EndGet

PublicProperty middleName()AsString

Get

Return uMname

EndGet

Set(ByVal valueAsString)

uMname = value

EndSet

EndProperty

PublicProperty visit()AsInteger

Get

Return uVisit

EndGet

Set(ByVal valueAsInteger)

If value < 0Then

uVisit = 0

Else

uVisit = value

EndIf

EndSet

EndProperty

EndClass
------- code
addbutton click
tempArray.Add(New userObject(txtlname2.Text, txtfname2.Text, txtmname2.Text))

tempArray.TrimToSize()

ListBox1.DataSource = tempArray

ListBox1.DataBind()
------output
listbox :
object1.userobject
-----how do i get it to display the info in the object
listbox:
bob, doe, smith
----------

thanks

i think i got it figured out solution:
---------------
tempArray.Add(New userObject(txtlname2.Text, txtfname2.Text, txtmname2.Text))
tempArray.TrimToSize()

ForEach obj1In tempArray

strSelection = obj1.lastName &", " & obj1.firstName &", " & obj1.middleName

If Len(LTrim(strSelection)) > 0Then

ListBox1.Items.Add(strSelection)

ListBox1.SelectedIndex = 0

EndIf

Next
i left out the binding method...........i'm not sure this is the best way ,,,,,,if someone knows of a better way please post .......
thanks

0 comments:

Post a Comment