473,396 Members | 1,966 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,396 software developers and data experts.

multiple selection from checkboxes into text box

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

Any help with this would be awesome

Apr 5 '06 #1
7 5438
"Demonicpagan" <De**********@gmail.com> wrote in message
news:11**********************@t31g2000cwb.googlegr oups.com...

' 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
I'm sure someone'll pop in with some real help... in the mean time, I'm
wondering why you're clearing then appending text to a textbox.

You should be able to replace this..... If worldChk.Checked = True Then
signatureTxt.Text = ""
signatureTxt.Text = signatureTxt.Text & bbworld
End If
....with.... If worldChk.Checked = True Then
signatureTxt.Text = bbworld
End If


Depending on the details, I might code it like this in VB5/6
'========
Option Explicit

Private mobjCheckBoxes As Collection

Private Sub Form_Load()
Set mobjCheckBoxes = New Collection

Check1.Tag = "Name"
Check2.Tag = "Address"

'I like to build my own collection instead of looping through
'the entire Controls collection each time
mobjCheckBoxes.Add Check1
mobjCheckBoxes.Add Check2

End Sub

Private Sub Command1_Click()
Dim c As CheckBox

With Text1
.Text = "" 'clear all text

'Loop through the collection, looking for 'checked' boxes
'appending the Tag property to the textbox
'I'm sure dotNet has something similar
For Each c In mobjCheckBoxes
If c.Value = vbChecked Then
.SelText = " " & c.Tag
'Reset Cursor = end of all text
.SelStart = Len(.Text)
End If
Next

End With

End Sub
'========

--
Ken Halter - MS-MVP-VB (visiting from VB6 world) - http://www.vbsight.com
Please keep all discussions in the groups..
Apr 5 '06 #2
Demonicpagan wrote:
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

Any help with this would be awesome


For Each C as Control in Me.Controls
if typeof c is checkbox then
if directcast(c, checkbox).checked then
signatureTxt.Text += C.Name
end if
end if
Next

That might not be the exact code, but it's close.

good luck
Apr 5 '06 #3
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

Apr 6 '06 #4
Just for knowledge purposes, I am using Visual Basic 2005 Express
Edition to code this

Apr 6 '06 #5
I probably should also ask this while I'm at it because I know it will
be something that I will be asking.

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?

Apr 6 '06 #6
Is there anyone that can help me with this?

Apr 9 '06 #7
Still looking for some help with this

Apr 10 '06 #8

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

Similar topics

3
by: Lori Costache | last post by:
Hi guys, I have a problem with multiple selection I have a list with 8 options in pull-down menu. For each option I have a price. Something like that :Element Price Table 10 Sofa ...
2
by: DK | last post by:
Hello everybody ! I need little help from Your side. I have form called Form2, and ListBox called List 20. Property of List 20 allow multiple selection. Also I have query called Distribution as...
2
by: Jensen bredal | last post by:
Hello, Can someone guide me in how i may process a multiple selection on a databound checkboxlist? The checkboxlist is bound to a table of product category. The product category id is an FK in...
1
by: Brent Baker | last post by:
Is there a way to change a CListBox from single selection to multiple selection, or back again, from inside the program after the CListBox has been created? Our application has several...
1
by: Michael Groeger | last post by:
Hi, I want to be able to have a DropDownList which supports multiple selection, but I haven't found a property for that in the DropDownList control. Is there a way to have multiple selection...
1
by: Eddy Balan | last post by:
Hi. Please help me....... I would like to copy the datagrid contents to clipboard and then to paste it into Excel but I can't make a multiple selection. Eddy
10
by: ads | last post by:
hi, after binding the dropdownlist to a datasource, ive experience this error "Cannot have multiple items selected in a dropdownlist" after using the code:...
2
by: ggk517 | last post by:
I have a script like below: ------------------------------------------------------------------------------------------------------------------------ <html> <head> <title>TEST</title> <script...
4
by: bansh | last post by:
Hi all, As question title I need a javascript which provides the facility to make multiple selection without holding control key. Means I how is it possible to make multiple selection/deselction...
1
by: shidram | last post by:
Hello sir, I have problem while using javascript with HTML multiple selection tag, I want to write javascript in such a way that if a I change the option by clicking on the radio button on html...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...

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.