473,569 Members | 2,916 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Make string-array from checkboxlist

Mabye this is question is very simple, but I need to make a string-array (in
a variable) with the values from a checkbox-list.

THANKS :)
Nov 2 '06 #1
2 6887
Got it:
//Make sting-Array:
string[] arrInterest = new string[1000];
for (int i = 0; i < chkInterests.It ems.Count; i++)
{
if (chkInterests.I tems[i].Selected)
{
arrInterest[i] = (string)chkInte rests.Items[i].Text;
}
}
"Øyvind Isaksen" <ho***@egmont.n owrote in message
news:O$******** ******@TK2MSFTN GP03.phx.gbl...
Mabye this is question is very simple, but I need to make a string-array
(in a variable) with the values from a checkbox-list.

THANKS :)

Nov 2 '06 #2
On Thu, 02 Nov 2006 10:39:48 +0100, Øyvind Isaksen <ho***@egmont.n owrote:
Got it:
//Make sting-Array:
string[] arrInterest = new string[1000];
for (int i = 0; i < chkInterests.It ems.Count; i++)
{
if (chkInterests.I tems[i].Selected)
{
arrInterest[i] = (string)chkInte rests.Items[i].Text;
}
}

This will create an unecessary long list with plenty of empty lines.

To limit the size to no more than the size of the CheckBoxList use

string[] arrInterest = new string[chkInterests.It ems.Count];

But even this will create empty spaces. To create a size of only selected
items use a List<Tand possibly its ToArray

List<stringsele ction = new List<string>();
foreach (ListItem li in CheckBoxList1.I tems)
{
if (li.Selected)
selection.Add(l i.Text);
}

Swap List with ArrayList if you are using framework 1.1

--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 2 '06 #3

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

Similar topics

7
1422
by: Daniel | last post by:
how to make two references to one string that stay refered to the same string reguardless of the changing value in the string?
19
1958
by: pkilambi | last post by:
I wrote this function which does the following: after readling lines from file.It splits and finds the word occurences through a hash table...for some reason this is quite slow..can some one help me make it faster... f = open(filename) lines = f.readlines() def create_words(lines): cnt = 0 spl_set = '+' for content in lines:
10
5745
by: DataBard007 | last post by:
Hello Access Gurus: I use Win98SE and Access97. I just built a simple Access97 application which holds all contact information for my personal contacts, such as first name, last name, address, city, state, etc. When the user wants to search for a particular record, he does two things: 1. On the form is a text box on which he enters the...
42
4915
by: WindAndWaves | last post by:
Dear All Can you tell me why you use a class module??? Thank you Nicolaas ---
1
4195
by: PCB | last post by:
Hi all, Not sure if this is possible, but can I change the controls of a command button on a per record bases in a subform. In my case, I would like to make a command button visible only if certain fields in a table are a certain value. The buttons are adjacent to each record (i.e. - if there are 5 records, there would be 5 buttons; 10...
1
1797
by: Robert | last post by:
Vb.Net Make dll that contain one function. Help Please. I would like to call a function from different applications. I think i have to make a dll. I have Visual Basic.net 2003 Standard Edition, that teorically does not make dll, but pratically does. I search vbc.exe and copy it to a new folder, in which i have the
10
2165
by: Extremest | last post by:
I know there are ways to make this a lot faster. Any newsreader does this in seconds. I don't know how they do it and I am very new to c#. If anyone knows a faster way please let me know. All I am doing is quering the db for all the headers for a certain group and then going through them to find all the parts of each post. I only want...
4
2764
by: Kyote | last post by:
I'm trying to persist a list of filenames. I've made a custom collection and a FileName class: 'Class to hold file name information Public Class FileNames Public fullName As String Public fileName As String Public fileExtention As String Public filePath As String Public newName As String
18
2654
by: active | last post by:
Console.WriteLine(String.Equals(s, s.Clone.ToString)) s is type string. This returns True. If Clone really made a new copy I'd expect False.
16
1852
by: InDepth | last post by:
Now that .NET is at it's fourth release (3.5 is coming soon), my very humble question to the gurus is: "What have we won with the decision to have string objects immutable? Or did we won?" Ok. It's a broad, and maybe a very silly question to ask, but still. I mean, what good has it brought to us? What advantages immutable strings have...
0
7693
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8118
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7665
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6277
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5501
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2105
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 we have to send another system
1
1207
muto222
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.