Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
I'm working on an application which requires me to take the items that a user selects from a multi-select ListBox, and put them into another ListBox on another form. I basically just want to add the selected items in the ListBox to an array, and then call on that array to fill the ListBox on the other form. I've looked all around this site and Google for how to do this, and I all I can really find is how to do it in VB6, I need to know how in .NET. Thanks!
Posted
I'm kinda new to using arrays, and I have just fiddled around with the CopyTo method, but can't seem to make it work. What is the proper way to declare my array, and what is the proper way to use the ListBox's CopyTo command to fill that array? I appreciate the help, thanks.
  • Leaders
Posted

I would think that in most cases, you could use the .SelectedItems collection in place of an array. If you need the items in the form of an array, however, here:

 

'Try using a more specific type, such as String if the listbox contains strings
       Dim X As Object() 'Declare Variable
       X = New Object(ListBox1.SelectedItems.Count - 1) {} 'Create properly sized array
       ListBox1.SelectedItems.CopyTo(X, 0) 'Copy selected items to the array

[sIGPIC]e[/sIGPIC]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...