Click to See Complete Forum and Search --> : Radio Buttons...????
rajtofar
July 16th, 2002, 01:16 AM
Hi all,
I am developing an app. in Vb .net that has a form with a no. of radio buttons. Much like a multiple choice Questionaire(4 choices for each question).
Once the user selects the options, and clicks on save, I need to write them in An excel sheet.
Vb6 had control arrays which made this simple, but Vb .net ..... I don't know how to do this.
Pl. help.
raj2far
John G Duffy
July 19th, 2002, 02:29 PM
VB.Net has an equivelent of control arrays but you must set up the events that you wish to handle multiple controls yourself.
In the Sample below, I created a new project and added 4 option buttons. To handle all the option buttons in the same events, I altered the Button1_CheckChanged Sub to include buttons 2,3 and 4.
I doubled clicked RadioButton1 and was presented the following
Private Sub RadioButton1_CheckedChanged(Byval sender as System.Object,_
Byval e as System.EventArgs) _
Handles RadioButton1.CheckedChanged
'
I changed that statement to read
'
Private Sub RadioButton1_CheckedChanged(Byval sender as System.Object,_
Byval e as System.EventArgs) _
Handles RadioButton1.CheckedChanged, _
RadioButton2_CheckedChanged, _
RadioButton3_CheckedChanged, _
RadioButton4_CheckedChanged
There may be a better way, but the big book I am reading on VB.net says this is the only way to manage "control arrays" in VB.Net
sxcostanzo
July 19th, 2002, 03:27 PM
That's what my book says also.....
However, I am running into an issue where I have 8 list boxes with the same information (The user can choose 8 out of 30 items to graph). There are 8 labels to the left of these list boxes that I set colors to.
In .NET it seems like I have to do
lblItem1.BackColor =
lblItem2.BackColor =
...
lblItem8.BackColor =
as opposed to either using a control array in vb6 or even
For intI = 1 to 8
me.controls("lblItem" & intI).BackColor
next
So my question is: Is there a way to do the control looping? It seems like the controls are based upon integers as opposed to putting the name in.
rajtofar
July 22nd, 2002, 12:09 AM
WEll, I've found out a way to do this...
along with the handles on clicks, we can loop the controls by their tab index. This is much like doing...
arr(0) = "something"
arr(1) = something else"
....
....
...
arr(20) = "more"
here's how to do it.
radiobutton1.tabindex =1
radiobutton2.tabindex = 2
....
Now we can incorporate them by using a "for each" loop.
somewhat like this.....
ctrl = New Object()
control = New System.Windows.Forms.RadioButton()
Dim ctl As System.Windows.Forms.RadioButton
ctl = New System.Windows.Forms.RadioButton()
For Each ctrl In Me.Panel1.Controls
For Each control In ctrl.controls
If control.GetType Is ctl.GetType Then
If control.checked = True Then
Call showdetails(control)
'MsgBox(control.name)
End If
End If
' MsgBox(control.name)
Next control
Next ctrl
Now here I have a panel which have some 10 groupboxes.
Each groupbox has one label and four radiobuttons.
then, in the loop I call a function 'showdetails' which is somewhat like this....
Public Sub showdetails(ByVal sender As System.Object)
'Dim buttonControl As RadioButton = buttonControl
Select Case (sender.TabIndex)
Case 1
' MessageBox.Show(buttonControl.TabIndex)
array(0) = 1
Case 2
' MessageBox.Show(buttonControl.TabIndex)
array(0) = 2
Case 3
' MessageBox.Show(buttonControl.TabIndex)
array(0) = 3
Case 4
array(0) = 4
Case 5
array(1) = 1
Case 6
array(1) = 2
Case 7
array(1) = 3
Case 8
....
..
end select
I hope this clears every one's doubts. It did clear mine..
Thnks for the help.
rajtofar
Originally posted by sxcostanzo
That's what my book says also.....
However, I am running into an issue where I have 8 list boxes with the same information (The user can choose 8 out of 30 items to graph). There are 8 labels to the left of these list boxes that I set colors to.
In .NET it seems like I have to do
lblItem1.BackColor =
lblItem2.BackColor =
...
lblItem8.BackColor =
as opposed to either using a control array in vb6 or even
For intI = 1 to 8
me.controls("lblItem" & intI).BackColor
next
So my question is: Is there a way to do the control looping? It seems like the controls are based upon integers as opposed to putting the name in.
sxcostanzo
July 22nd, 2002, 09:20 AM
The only problem with using the tab index is that it also is the ORDER in which the user goes through the screen. I guess it would work if those were the only controls the user went through, however if they are halfway down your form, wouldn't that be a problem?
rajtofar
July 23rd, 2002, 01:02 AM
Hi...
I guess its the same as "you win some you loose some".
Is there any other way out??
I couldn't find anything else.
:rolleyes:
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.