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

Please Help ! Radio Buttons question

Hi,

I had to improvise a control that looks like a list view with each row
holding 3 radio buttons. To do this I am using a panel (mainPanel)
that holds other panels representing rows (rowPanel).

So, I fetch database and for each item, I add a rowPenel with 3 radio
buttons to the mainPanel.

Now, for each row, there must be one radio button selected. To check
that, I do:

For i = 0 To mainPanel.Controls.Count - 1
Dim rowPanel as Panel = mainPanel.Controls.item(i)
Dim aRadioButton as RadioButton

For Each aRadioButton in rowPanel.Controls
If aRadioButton.Checked = True Then
blnFound = True
End If
End For

If blnFound = False Then
ErrorMessage()
End If

End For

The problem is that even though I check a radio button, blnFound will
be still false. Can somebody tell what I am doing wrong?

Thank you
Nov 21 '05 #1
4 1315
Your code looks a bit odd to me. Perhaps you are getting messed up because
there are controls on the mainPanel that aren't panels? Try something like:

Dim Ctl As Control
Dim pnlCtl As Control
For Each Ctl In mainPanel.controls
If TypeOf Ctl Is Panel Then
For Each pnlCtl In Ctl.Controls
If TypeOf pnlCtl Is RadioButton Then
blnFound = False
If pnlCtl.Checked = True Then
blnFound = True
End If
End If
Next
End If
If blnFound = False Then
ErrorMsg()
Exit For
End If
Next
Terp
"Dino Buljubasic" <di**@noplacelikehome.com> wrote in message
news:kp********************************@4ax.com...
Now, for each row, there must be one radio button selected. To check
that, I do:

For i = 0 To mainPanel.Controls.Count - 1
Dim rowPanel as Panel = mainPanel.Controls.item(i)
Dim aRadioButton as RadioButton

For Each aRadioButton in rowPanel.Controls
If aRadioButton.Checked = True Then
blnFound = True
End If
End For

If blnFound = False Then
ErrorMessage()
End If

End For

The problem is that even though I check a radio button, blnFound will
be still false. Can somebody tell what I am doing wrong?

Thank you

Nov 21 '05 #2
Thank you,

It works fine now

Dino

On Tue, 4 Jan 2005 13:43:46 -0800, "Terp" <ct*********@comcast.net>
wrote:
Your code looks a bit odd to me. Perhaps you are getting messed up because
there are controls on the mainPanel that aren't panels? Try something like:

Dim Ctl As Control
Dim pnlCtl As Control
For Each Ctl In mainPanel.controls
If TypeOf Ctl Is Panel Then
For Each pnlCtl In Ctl.Controls
If TypeOf pnlCtl Is RadioButton Then
blnFound = False
If pnlCtl.Checked = True Then
blnFound = True
End If
End If
Next
End If
If blnFound = False Then
ErrorMsg()
Exit For
End If
Next
Terp
"Dino Buljubasic" <di**@noplacelikehome.com> wrote in message
news:kp********************************@4ax.com.. .
Now, for each row, there must be one radio button selected. To check
that, I do:

For i = 0 To mainPanel.Controls.Count - 1
Dim rowPanel as Panel = mainPanel.Controls.item(i)
Dim aRadioButton as RadioButton

For Each aRadioButton in rowPanel.Controls
If aRadioButton.Checked = True Then
blnFound = True
End If
End For

If blnFound = False Then
ErrorMessage()
End If

End For

The problem is that even though I check a radio button, blnFound will
be still false. Can somebody tell what I am doing wrong?

Thank you


Nov 21 '05 #3
> For Each aRadioButton in rowPanel.Controls
If aRadioButton.Checked = True Then
blnFound = True
End If
End For


Step through this Loop

First Iteration:
blnFound = RadioButton1.Checked

Second Iteration:
blnFound = RadioButton2.Checked

Third Iteration:
blnFound = RadioButton3.Checked

Answer this question:

What is the Value of blnFound if RadioButton3.Checked = False?
Secondly, don't use a For Each RadioButton Loop. Loop through the Controls
and check the current controls type against RadioButton...

\\\
For Each PanelControl As Control In Panel.Controls
If TypeOf PanelControl Is RadioButton Then
If blnFound = False Then
blnFound = CType(PanelControl, RadioButton).Checked
End If
End If
Next
///

Alternatively, use a Do Loop

\\\
Dim Index As Integer = 0

Do
If TypeOf Panel.Controls(Index) Is RadioButton Then
blnFound = CType(Panel.Controls(Index), RadioButton).Checked
End If
Index += 1
Loop Until blnFound = True OrElse Index >= Panel.Controls.Count
///

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
Nov 21 '05 #4
Forget the first part of my answer, I should have been asleep when I
responded to this, and looking back on it now, it seems I was.

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Mick Doherty"
<EX***********@AND.REMOVE.SQUAREBRACKETS.[mdaudi100#ntlworld.com]> wrote in
message news:ui**************@tk2msftngp13.phx.gbl...
For Each aRadioButton in rowPanel.Controls
If aRadioButton.Checked = True Then
blnFound = True
End If
End For


Step through this Loop

First Iteration:
blnFound = RadioButton1.Checked

Second Iteration:
blnFound = RadioButton2.Checked

Third Iteration:
blnFound = RadioButton3.Checked

Answer this question:

What is the Value of blnFound if RadioButton3.Checked = False?
Secondly, don't use a For Each RadioButton Loop. Loop through the Controls
and check the current controls type against RadioButton...

\\\
For Each PanelControl As Control In Panel.Controls
If TypeOf PanelControl Is RadioButton Then
If blnFound = False Then
blnFound = CType(PanelControl, RadioButton).Checked
End If
End If
Next
///

Alternatively, use a Do Loop

\\\
Dim Index As Integer = 0

Do
If TypeOf Panel.Controls(Index) Is RadioButton Then
blnFound = CType(Panel.Controls(Index), RadioButton).Checked
End If
Index += 1
Loop Until blnFound = True OrElse Index >= Panel.Controls.Count
///

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html

Nov 21 '05 #5

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

Similar topics

4
by: Oscar Monteiro | last post by:
I Have to sets of Radio buttons like so: <input type="radio" name=p1 value=1> <input type="radio" name=p1 value=2> <input type="radio" name=p1 value=3> <br> <input type="radio" name=p2 value=1>...
3
by: Jay | last post by:
I noticed somewhere on the net that a post mentioned that there was a bug in the datagrid, radio buttons and a repeater. Something about the radio buttons are not mutually exclusive. (will this be...
3
by: Ken Varn | last post by:
This is probably a simple question, but I am new to this so bear with me. I have a ASP.NET form that has a checkbox and a 2 radio buttons. When the checkbox is checked, the 2 radio buttons are...
1
by: Jerry | last post by:
We have a 10-question quiz for kids, each question being a yes or no answer using radio selections. I'd like to keep a current total of yes's and no's at the bottom of the quiz (if the user selects...
12
html on wheels
by: html on wheels | last post by:
Greeting sports fans. In order to ask multiple questions and not have your radio buttons jump from one question to the next, what do you type to create a break between them. I am trying to complete a...
2
by: dpazza | last post by:
Hi, I'm creating a quiz on using a form in VB 2005 express. I have four sets of questions and answers (labels and radio buttons) and I change between which set of questions is currently shown on...
4
by: Blasting Cap | last post by:
I have a page that has a number of radio buttons that will be displayed to different access levels of a user who logs in to my website. For instance, if there are a dozen buttons, user1 will see...
5
by: alanb | last post by:
Hi, hope someone can help, I need to be able to keep a running total of radio buttons selected, as a user goes through a set of 16 questions, devided in to 4 catorgories, then on "submit" have the...
4
by: CURTISLESPERANCE | last post by:
Hi, I am trying to figure out if this is possible. I need to display 4 radio buttons next to a question then 3 radio buttons after. The 2 different group radio buttons and questions are coming from...
11
by: Twayne | last post by:
Hi, Newbie to PHP here, no C or other relevant background, so pretty niave w/r to the nuances etc. but I think this is pretty basic. XP Pro, SP2+, PHP 4.4.7, XAMPP Local Apache Server...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.