PaulieORF Posted March 13, 2005 Posted March 13, 2005 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! Quote
Administrators PlausiblyDamp Posted March 14, 2005 Administrators Posted March 14, 2005 The list box should have a SelectedItems property, could you not use it's .CopyTo method? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
PaulieORF Posted March 14, 2005 Author Posted March 14, 2005 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. Quote
Leaders snarfblam Posted March 14, 2005 Leaders Posted March 14, 2005 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 Quote [sIGPIC]e[/sIGPIC]
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.