473,480 Members | 2,300 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

ListBox.SelectedItems to string array

Hi
I am trying to pass the selected items from a multiselect listbox to a
string array. Can any body give me a start.
Thanks

Colin Williams

Oct 18 '06 #1
2 23151
Try this:

listBox1.Items.Add("this");
listBox1.Items.Add("is");
listBox1.Items.Add("a");
listBox1.Items.Add("test");

string[] destination = new string[listBox1.Items.Count];

listBox1.Items.CopyTo(destination, 0);

That example uses the Items collection but the SelectedItems collection
work work just the same, it's the CopyTo function you should be looking
at.
Kelly S. Elias
Webmaster
http://devdistrict.com
Colin Williams wrote:
Hi
I am trying to pass the selected items from a multiselect listbox to a
string array. Can any body give me a start.
Thanks

Colin Williams
Oct 18 '06 #2
Thanks
Had the code there but commented out! Must have threw inadvertent
errors. Code blindness perhaps.
Thanks once again
Cryptik wrote:
Try this:

listBox1.Items.Add("this");
listBox1.Items.Add("is");
listBox1.Items.Add("a");
listBox1.Items.Add("test");

string[] destination = new string[listBox1.Items.Count];

listBox1.Items.CopyTo(destination, 0);

That example uses the Items collection but the SelectedItems collection
work work just the same, it's the CopyTo function you should be looking
at.
Kelly S. Elias
Webmaster
http://devdistrict.com
Colin Williams wrote:
Hi
I am trying to pass the selected items from a multiselect listbox to a
string array. Can any body give me a start.
Thanks

Colin Williams
Oct 18 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2834
by: Goh, Yong Kwang | last post by:
I'm trying to create a function that given a string, tokenize it and put into a dynamically-sized array of char* which is in turn also dynamically allocated based on the string token length. I...
8
13934
by: Jeff Johnson | last post by:
Hi, I've begun converting an ASP site over to .NET and I'm a novice at both the new platform as well as C#. I have a COM+ object that returns a string array when it is called. The size of...
11
17617
by: Zordiac | last post by:
How do I dynamically populate a string array? I hope there is something obvious that I'm missing here Option Strict On dim s() as string dim sTmp as string = "test" dim i as integer ...
1
1270
by: Linda Jose | last post by:
I have a string array. How to load the data from string array to the list box? I am using VB.Net and .NetFramework 1.1. Thanks, Jose
5
28301
by: Paulers | last post by:
Hello all, I have a string array with duplicate elements. I need to create a new string array containing only the unique elements. Is there an easy way to do this? I have tried looping through...
6
6073
by: Niyazi | last post by:
Hi all, What is fastest way removing duplicated value from string array using vb.net? Here is what currently I am doing but the the array contains over 16000 items. And it just do it in 10 or...
6
2325
by: Paul | last post by:
Hi All, Framework 1.1 listbox control unable to DataBind I've been googling for an answer to this query that appears quite a lot, but none, it seem, answers my problem directly. I am...
3
3979
by: papa smerf | last post by:
'Here is some of the code I have so far. Dim Contacts(25, 4) As String This is where I add to the listbox Private Sub btnAddToList_Click(ByVal sender As System.Object, ByVal e As...
1
2411
by: Peter van der Zee | last post by:
L.S., I'm want to fill a Listbox with class Array "records" based on certain criteria. The idea is to be able to select one "record" at the time, modify the data, and display this "changed"...
0
7048
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7091
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6743
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6966
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5344
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4488
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2988
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1303
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
564
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.