On my form I have 10 checkboxes named chkbox1,chkbox2,....chkbox10. I would
have like to set it up as an array control like in VB6 where I could have
chkbox(1),chkbox(2) but I think .net you have to have specific names for
each control. All 10 of the boxes are in a groupbox. What I'm trying to do
is when I hit a button it will loop through all the checkboxes to see which
ones are checked and add that checkbox name to a string. Something like
Names = chkbox1.text & " " chkbox2.text & " " ect... Once I got a list of
all the ones that were checked all 10 would be reset and unchecked to start
over.
Thanks,
Tim 8 42045
"Tim" <dg******@maine.rrdotcom> scripsit: On my form I have 10 checkboxes named chkbox1,chkbox2,....chkbox10. I would have like to set it up as an array control like in VB6 where I could have chkbox(1),chkbox(2) but I think .net you have to have specific names for each control. All 10 of the boxes are in a groupbox. What I'm trying to do is when I hit a button it will loop through all the checkboxes to see which ones are checked and add that checkbox name to a string. Something like Names = chkbox1.text & " " chkbox2.text & " " ect... Once I got a list of all the ones that were checked all 10 would be reset and unchecked to start over.
Creating Control Arrays in Visual Basic .NET and Visual C# .NET
<http://msdn.microsoft.com/library/?url=/library/en-us/dv_vstechart/html/vbtchCreatingControlArraysInVisualBasicNETVisualCN ET.asp>
--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
"Tim" <dg******@maine.rrdotcom> schrieb On my form I have 10 checkboxes named chkbox1,chkbox2,....chkbox10.
You can use expressive names instead of numbers.
I would have like to set it up as an array control like in VB6 where I could have chkbox(1),chkbox(2) but I think .net you have to have specific names for each control.
You don't have to, but you can.
All 10 of the boxes are in a groupbox. What I'm trying to do is when I hit a button it will loop through all the checkboxes to see which ones are checked and add that checkbox name to a string. Something like Names = chkbox1.text & " " chkbox2.text & " " ect... Once I got a list of all the ones that were checked all 10 would be reset and unchecked to start over.
You can still put the Checkboxes into an array:
Once (in constructor or in OnLoad):
Dim AllCheckboxes As CheckBox() = {chk1, chk2, chk3, ... chkbox10}
Later:
dim chk as checkbox
dim sb as new system.text.stringbuilder
dim names as string
for each chk in allcheckboxes
if chk.checked Then
sb.append(chk.text)
sb.append(" "c)
chk.check = false
end if
next chk
names = sb.tostring(0, sb.length - 1)
_Instead_ of the array (AllCheckboxes), you can loop through the controls in
the GroupBox:
dim chk as checkbox
for each chk in mygroupbox.controls
'same as above
next chk
If there are also other types of controls in the same groupbox:
dim o as object
for each o in mygroupbox.controls
if typeof o is checkbox then
dim chk as checkbox
chk = directcast(o, checkbox)
'same as above
end if
next chk
--
Armin
1) You could create an array that contains a reference to each of the
checkboxes. Just add them manually. Just because you can't have control
arrays alla VB6 doesn't mean you can't use arrays.
2) If the form has all of the checkboxes you are interested in, and you
don't expect to have more, you can loop through the controls collection of
the form (For each chk as Checkbox in me.controls)
3) You can add all the checkboxes to a panel and do the same as #2 but the
panel's controls. This gives you a little more extensibility.
I'm sure there are more ways.
"Tim" <dg******@maine.rrdotcom> wrote in message
news:T0*****************@twister.nyroc.rr.com... On my form I have 10 checkboxes named chkbox1,chkbox2,....chkbox10. I
would have like to set it up as an array control like in VB6 where I could have chkbox(1),chkbox(2) but I think .net you have to have specific names for each control. All 10 of the boxes are in a groupbox. What I'm trying to
do is when I hit a button it will loop through all the checkboxes to see
which ones are checked and add that checkbox name to a string. Something like Names = chkbox1.text & " " chkbox2.text & " " ect... Once I got a list of all the ones that were checked all 10 would be reset and unchecked to
start over.
Thanks,
Tim
Hi Tim, On my form I have 10 checkboxes named chkbox1,chkbox2,....chkbox10. I
would have like to set it up as an array control like in VB6 where I could have chkbox(1),chkbox(2) but I think .net you have to have specific names for each control. All 10 of the boxes are in a groupbox. What I'm trying to
do is when I hit a button it will loop through all the checkboxes to see
which ones are checked and add that checkbox name to a string. Something like Names = chkbox1.text & " " chkbox2.text & " " ect... Once I got a list of all the ones that were checked all 10 would be reset and unchecked to
start over.
Something like this I think.
\\\\
dim strb as system.text.stringbuilder
Dim ctr As Control
Dim a As New System.Text.StringBuilder
For Each ctr In Me.GroupBox1.Controls
Dim ctrchk As CheckBox = DirectCast(ctr, CheckBox)
If ctrchk.Checked Then
strb.Append(ctrchk.Name.ToString)
End If
Next
dim strEnd as string = strb.tostring
////
I hope this helps a little bit
Cor
Here is an article I submitted to PSC which may help you.
Matt http://www.planetsourcecode.com/vb/s...1376&lngWId=10
"Tim" <dg******@maine.rrdotcom> wrote in message
news:T0*****************@twister.nyroc.rr.com... On my form I have 10 checkboxes named chkbox1,chkbox2,....chkbox10. I
would have like to set it up as an array control like in VB6 where I could have chkbox(1),chkbox(2) but I think .net you have to have specific names for each control. All 10 of the boxes are in a groupbox. What I'm trying to
do is when I hit a button it will loop through all the checkboxes to see
which ones are checked and add that checkbox name to a string. Something like Names = chkbox1.text & " " chkbox2.text & " " ect... Once I got a list of all the ones that were checked all 10 would be reset and unchecked to
start over.
Thanks,
Tim
"Tim" <dg******@maine.rrdotcom> wrote in message news:<T0*****************@twister.nyroc.rr.com>... On my form I have 10 checkboxes named chkbox1,chkbox2,....chkbox10. I would have like to set it up as an array control like in VB6 where I could have chkbox(1),chkbox(2) but I think .net you have to have specific names for each control. All 10 of the boxes are in a groupbox. What I'm trying to do is when I hit a button it will loop through all the checkboxes to see which ones are checked and add that checkbox name to a string. Something like Names = chkbox1.text & " " chkbox2.text & " " ect... Once I got a list of all the ones that were checked all 10 would be reset and unchecked to start over.
Thanks,
Tim
Dim ctrl as Control
Dim ChkBx as CheckBox
For each ctrl in GroupBox.Controls
If ctrl.GetType is ChkBx.GetType Then
ctrl = DirectCast(ctl, CheckBox)
If ctrl.Checked Then
'do stuff
End If
End If
Next
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim c As System.Windows.Forms.CheckBox
For Each c In GroupBox1.Controls()
c.Checked = True
Next
end Sub
Armin Zingler wrote: "Tim" <dg******@maine.rrdotcom> schrieb On my form I have 10 checkboxes named chkbox1,chkbox2,....chkbox10.
You can use expressive names instead of numbers.
I would have like to set it up as an array control like in VB6 where I could have chkbox(1),chkbox(2) but I think .net you have to have specific names for each control.
You don't have to, but you can.
All 10 of the boxes are in a groupbox. What I'm trying to do is when I hit a button it will loop through all the checkboxes to see which ones are checked and add that checkbox name to a string. Something like Names = chkbox1.text & " " chkbox2.text & " " ect... Once I got a list of all the ones that were checked all 10 would be reset and unchecked to start over.
You can still put the Checkboxes into an array:
Once (in constructor or in OnLoad): Dim AllCheckboxes As CheckBox() = {chk1, chk2, chk3, ... chkbox10}
Later: dim chk as checkbox dim sb as new system.text.stringbuilder dim names as string
for each chk in allcheckboxes if chk.checked Then sb.append(chk.text) sb.append(" "c) chk.check = false end if next chk
names = sb.tostring(0, sb.length - 1)
_Instead_ of the array (AllCheckboxes), you can loop through the controls in the GroupBox:
dim chk as checkbox for each chk in mygroupbox.controls 'same as above next chk
If there are also other types of controls in the same groupbox: dim o as object for each o in mygroupbox.controls if typeof o is checkbox then dim chk as checkbox chk = directcast(o, checkbox) 'same as above end if next chk
"One Handed Man" <Bo****@Duck.net> schrieb Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim c As System.Windows.Forms.CheckBox
For Each c In GroupBox1.Controls()
c.Checked = True
Next
end Sub
I'm trying to figure out the difference. Ok, I accidently wrote "chk.check =
False" (not checkED) instead, but that's all I can see.
--
Armin This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: jeffsnox |
last post by:
Hi,
I have multiple checkboxes on the same form as follows:
<input type='checkbox' name='cbtype' value='1'>
<input type='checkbox' name='cbtype' value='2'>
<input type='checkbox'...
|
by: ramapv |
last post by:
can i highlight a checkbox from a group of checkbox with particular name which is given as a search key.
I am having a list of checkboxes and i have to select some of them and form a group.but i'm...
|
by: favor08 |
last post by:
I have a continious subform that 9000 + records and I have serveral
check marks on the subform. so it ties to that record.
Does anyone have any examples were they use multiple checkboxes in a ...
|
by: dream2rule |
last post by:
Hello All,
I am trying to validate multiple checkboxes whose values are stored in an array using php. I have been trying from a really long time but nothing's working out.
Can anyone help?
...
|
by: serghei |
last post by:
I have already the insert form and the database. It's working to insert multiple data with multiple checkboxes. But I can't retrieve multiple data.
|
by: Ned Balzer |
last post by:
Hi,
Can anyone point me in the direction of a solution for validating
multiple checkboxes in an asp.net 2.0 page?
1) This is not a checkboxlist, it is a number of separate checkboxes
2) I do...
|
by: santoshjsh |
last post by:
hello everyone,
i have a gridview in which i have multiple checkboxes in a single column.
means for every row in the gridview i have four checkboxes in one column e.g Add, Delete, Print,...
|
by: raamay |
last post by:
hey experts, please advise me what is the best way to save multiple checkboxes value in a database. I have 6 checkboxes and i came across storing the values in a single column of a table which i dont...
|
by: kimmelsd33 |
last post by:
I am adding to my software. I have placed about 30 checkboxes on a form. Based on which checkboxes are selected, I want to print the values to a tab delimited text file. For instance, the first...
|
by: BabyLucifer666 |
last post by:
Hello All, (using Access2000)
I have a form with multiple unbound checkboxes. What I would like to do is have the user check whoever needs to take a specific training course. My database is...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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...
|
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...
|
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: 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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |