Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / February 2007

Tip: Looking for answers? Try searching our database.

How to convert the items in a listbox to an arraylist?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Philip - 26 Feb 2007 11:44 GMT
Hi,

I want to make an arraylist of all the items in a listbox.

Can I do it like this:

CType(lstSelectedList.DataSource, ArrayList)

Or is there a better way in VB.NET (Framework 1.1)

thanks

Philip
Patrick Steele - 26 Feb 2007 13:35 GMT
> Hi,
>
[quoted text clipped - 5 lines]
>
> Or is there a better way in VB.NET (Framework 1.1)

Maybe ListBox.Items.CopyTo would work for what you need?  Do you know
what each item in the ListBox actually is?  Strings?  Ints?  DataRows?

Signature

Patrick Steele
http://weblogs.asp.net/psteele

Philip - 26 Feb 2007 13:36 GMT
Hi, thanks,

all the items in the listbox are string values.

Philip

> > Hi,
> >
[quoted text clipped - 8 lines]
> Maybe ListBox.Items.CopyTo would work for what you need?  Do you know
> what each item in the ListBox actually is?  Strings?  Ints?  DataRows?
Patrick Steele - 26 Feb 2007 13:51 GMT
> Hi, thanks,
>
> all the items in the listbox are string values.

Then you should be able to create a string array equal to the number of
items in your listbox and use the CopyTo method to copy the items into
the string array.

Signature

Patrick Steele
http://weblogs.asp.net/psteele

Patrick Steele - 26 Feb 2007 13:58 GMT
> > Hi, thanks,
> >
[quoted text clipped - 3 lines]
> items in your listbox and use the CopyTo method to copy the items into
> the string array.

Sorry -- clarification:

You can copy the items into a string array and then create an arraylist
from the string array.  Something like this:

       Dim s(ListBox1.Items.Count) As String
       Dim al As New ArrayList

       ListBox1.Items.CopyTo(s, 0)
       al = New ArrayList(s)

Signature

Patrick Steele
http://weblogs.asp.net/psteele

Philip - 26 Feb 2007 13:42 GMT
Hi,

I tried to do it using 'CopyTo' but I got this compile error:

'System.Collections.ArrayList' cannot be converted to '1-dimensional array
of System.Object'.

Here is the code I tried:
lstSelectedList.Items.CopyTo(m_arrSelList, 0)

thanks for any help

Philip

> > Hi,
> >
[quoted text clipped - 8 lines]
> Maybe ListBox.Items.CopyTo would work for what you need?  Do you know
> what each item in the ListBox actually is?  Strings?  Ints?  DataRows?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.