473,320 Members | 1,910 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

looping through checkboxes

I have this form where I am trying to place items from checked boxes
into a text box. An image of what this form looks like is at
http://www.stelth2000inc.com/images/screen.png

Here is some code I have done for the first 2 check boxes, name and
world, they do what I want them to do, but for the rest of the check
boxes, the codes would be a bit minotonous. Is there a better way of
doing this, maybe checkedboxlist?
Private Sub sigBtn_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles sigBtn.Click
Dim bbname As String = "
[size=10]Name: " &
charNameTxt.Text & "[/size]
" & vbCrLf
Dim bbworld As String = "
[size=10]World: " &
worldCombo.SelectedItem & "[/size]
" & vbCrLf
' Name check box checked
If chNameChk.Checked = True Then
signatureTxt.Text = ""
signatureTxt.Text = signatureTxt.Text & bbname
End If
' World check box checked
If worldChk.Checked = True Then
signatureTxt.Text = ""
signatureTxt.Text = signatureTxt.Text & bbworld
End If
' Name & world check boxes checked
If chNameChk.Checked = True And worldChk.Checked = True Then
signatureTxt.Text = ""
signatureTxt.Text = signatureTxt.Text & bbname & bbworld
End If
End Sub
The way that i am wanting this to work is the user selects items that
they would want in a forum signature. Each check box is representative

of items in other tabs in this program (i.e. Name is the Character name

which is a text box in the General Tab, World is a combo box in that
same tab). The user can select as many as all the check boxes or as
little as one check box. I was clearing the box and appending text to
the box in case user makes selections, clicks create signature, changes

their mind and selects other items, and clicks create signature again.
I didn't want the new selections following the old selections, but
rather overwrite what was previously there.

Ultimately output would look something like this if user was to select
the Character Name & World check boxes:
color=blue][size=10]Name: character name[/size]
[size=10]World: character world[/size]

Just Name:
[size=10]Name: character name[/size]

Just World:
[size=10]Name: character name[/size]

World & Linkshell:
[size=10]World: character world[/size]

[size=10]Linkshell: linkshell[/size]

so on and so forth
The checkbox I have as Sex will be outputting either
[size=10]Sex: Male[/size]

or
[size=10]Sex: Female[/size]

based on what radio button was selected in the General Tab. How will I

need to go about handling this with the rest of what I'm trying to do?
Just for knowledge purposes, I am using Visual Basic 2005 Express
Edition to code this

Apr 10 '06 #1
1 1297
Hi,

No matter what path you decide to take you will have to do some coding.

What you want to do is use a StringBuilder and add items whenever needed.

Dim sb as new StringBuilder()

' Name check box checked
If chNameChk.Checked = True Then
sb.Append( bbname )
End If

' World check box checked
If worldChk.Checked = True Then
sb.Append( bbworld )
End If

' Repeat as needed
If chSexChk.Checked Then
sb.Append( bbsex )
End if

signatureTxt.Text = sb.ToString()

If you want to you could even store the strings in the CheckBox.Tag
property and simply do

For Each c as Control in Me.Controls
If c is GroupBox Then
For Each cb as CheckBox in c.Controls
If cb.Checked Then
sb.Append( cb.Tag.ToString() )
End If
Next
End If
Next
--
Happy Coding!
Morten Wennevik [C# MVP]
Apr 10 '06 #2

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

Similar topics

4
by: David | last post by:
Hello. I am looking for advice on what is "best practice" regarding looping through a form to check its checkboxes and associated data fields. Here is what I am trying to do (Here is the page...
2
by: Amy Snyder | last post by:
This is my firt .NET project so please bear with me. I have a form of checkboxes and all I want to do is loop through them all after the page has been submitted and have their values added to a...
2
by: Chris Devol | last post by:
VB.NET 2002. I have a large group of CheckBoxes. I want to check/uncheck all the boxes whenever the "Check All" box is checked/unchecked. I also want to be able to fill an array of flags based on...
7
by: astro | last post by:
I am not farmilar with the object model for webforms. I want to loop through the web form controls - pulling out the checkboxes on the form like the following: For Each ctrl In Me.Controls ...
8
by: Alan Silver | last post by:
Hello, I have a repeater that has code like this... <ItemTemplate> <asp:CheckBox ID="chkDelete" Text="" RunAt="server"/> .... other stuff goes here </ItemTemplate> There is a button below...
2
by: clinttoris | last post by:
Hello, If someone could help me it would be appreciated as I am not having much luck. I'm struggling with my asp code and have some questions relating to asp and oracle database. First...
2
by: Bart Van Hemelen | last post by:
The situation: I have a CheckBoxList cblTest, the items are disabled in cblTest_DataBound in a foreach (ListItem oItem in cblTest.Items) loop. I provide a link that calls a client-side JavaScript...
10
by: rn5a | last post by:
All the rows in a DataGrid, including the Header, are accompanied with a CheckBox. I want that when the CheckBox in the Header is checked, then all the CheckBoxes should automatically get checked....
1
by: piscarian | last post by:
Hi all, I m doing vb.net window application(Framework 1.1) for second hand book shop with ms access 2003 .It's just school project ,so database is not that big . I have books,customer and...
5
by: Esmeralda | last post by:
My situation: I have a dynamic form with checkboxes. The checkboxes are submitted and added to a database. They are a list. I want to compare the list with what is currently listed in the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.